Skip to content

Commit

Permalink
Merge branch 'main' into itaylevyofficial/58-run-error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 12, 2023
2 parents f2552db + aee609f commit 513e5f1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 29 deletions.
16 changes: 8 additions & 8 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ func InitCmd() *cobra.Command {
Short: "Initialize a RollApp configuration on your local machine.",
Run: func(cmd *cobra.Command, args []string) {
initConfig := GetInitConfig(cmd, args)
OutputCleanError(VerifyUniqueRollappID(initConfig.RollappID, initConfig))
utils.PrettifyErrorIfExists(VerifyUniqueRollappID(initConfig.RollappID, initConfig))
isRootExist, err := dirNotEmpty(initConfig.Home)
OutputCleanError(err)
utils.PrettifyErrorIfExists(err)
if isRootExist {
shouldOverwrite, err := promptOverwriteConfig(initConfig.Home)
OutputCleanError(err)
utils.PrettifyErrorIfExists(err)
if shouldOverwrite {
OutputCleanError(os.RemoveAll(initConfig.Home))
utils.PrettifyErrorIfExists(os.RemoveAll(initConfig.Home))
} else {
os.Exit(0)
}
}

addresses := initializeKeys(initConfig)
if initConfig.CreateDALightNode {
OutputCleanError(initializeLightNodeConfig(initConfig))
utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig))
}
initializeRollappConfig(initConfig)
OutputCleanError(initializeRollappGenesis(initConfig))
OutputCleanError(initializeRelayerConfig(ChainConfig{
utils.PrettifyErrorIfExists(initializeRollappGenesis(initConfig))
utils.PrettifyErrorIfExists(initializeRelayerConfig(ChainConfig{
ID: initConfig.RollappID,
RPC: defaultRollappRPC,
Denom: initConfig.Denom,
Expand All @@ -54,7 +54,7 @@ func InitCmd() *cobra.Command {
Denom: "udym",
AddressPrefix: AddressPrefixes.Hub,
}, initConfig))
OutputCleanError(WriteConfigToTOML(initConfig))
utils.PrettifyErrorIfExists(WriteConfigToTOML(initConfig))
printInitOutput(addresses, initConfig.RollappID)
},
Args: cobra.ExactArgs(2),
Expand Down
10 changes: 0 additions & 10 deletions cmd/config/init/utils.go

This file was deleted.

10 changes: 5 additions & 5 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func RegisterCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(initconfig.FlagNames.Home).Value.String()
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
initconfig.OutputCleanError(err)
initconfig.OutputCleanError(initconfig.VerifyUniqueRollappID(rollappConfig.RollappID, rollappConfig))
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(initconfig.VerifyUniqueRollappID(rollappConfig.RollappID, rollappConfig))
err = registerRollapp(rollappConfig)
initconfig.OutputCleanError(err)
utils.PrettifyErrorIfExists(err)
registerSequencerCmd, err := getRegisterSequencerCmd(rollappConfig)
initconfig.OutputCleanError(err)
utils.PrettifyErrorIfExists(err)
err = registerSequencerCmd.Run()
initconfig.OutputCleanError(err)
utils.PrettifyErrorIfExists(err)
printRegisterOutput(rollappConfig)
},
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ func RunCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
initconfig.OutputCleanError(err)
utils.PrettifyErrorIfExists(err)
startRollappCmd := getStartRollapCmd(rollappConfig)
var stderr bytes.Buffer
startRollappCmd.Stderr = &stderr
err = startRollappCmd.Start()
if err != nil {
errMsg := parseError(stderr.String())
initconfig.OutputCleanError(errors.New(errMsg))
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
fmt.Println("💈 The Rollapp sequencer is running on your local machine!")
fmt.Println("💈 EVM RPC: http://0.0.0.0:8545")
Expand All @@ -38,7 +38,7 @@ func RunCmd() *cobra.Command {
err = startRollappCmd.Wait()
if err != nil {
errMsg := parseError(stderr.String())
initconfig.OutputCleanError(errors.New(errMsg))
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package initconfig
package utils

import (
"os"

"github.com/fatih/color"
)

func OutputCleanError(err error) {
func PrettifyErrorIfExists(err error) {
if err != nil {
defer func() {
if r := recover(); r != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/config/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"os"

"github.com/dymensionxyz/roller/cmd/utils"
initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/test/config/init/testutils"
"github.com/stretchr/testify/assert"
)
Expand Down

0 comments on commit 513e5f1

Please sign in to comment.