Skip to content

Commit

Permalink
feat: implement error handling , Service stopper on Error and Improve…
Browse files Browse the repository at this point in the history
… Logging (HugoByte#57)

* fix: typo in logging

* chore: remove log formatter

* fix: dive version is now independent on kurtosis engine

* feat: update logging , implement verbose logging

* feat: implement stop service on starlark run failure

* feat: update logger

* feat: update eth package

* feat: update logger to handle logs to files

* refactor: refactor imports

* fix: stop spinner on error and print logs , handle file while starting icon node and fix multilog files

* chore: bump kurtosis sdk version
  • Loading branch information
shreyasbhat0 authored Jul 27, 2023
1 parent 2a89023 commit 94aa54b
Show file tree
Hide file tree
Showing 19 changed files with 666 additions and 376 deletions.
28 changes: 20 additions & 8 deletions cli/commands/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/hugobyte/dive/common"
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -48,10 +47,11 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
common.ValidateCmdArgs(args, cmd.UsageString())

diveContext.InitKurtosisContext()
enclaveCtx, err := diveContext.GetEnclaveContext()

if err != nil {
logrus.Errorln(err)
diveContext.Error(err.Error())
}
diveContext.StartSpinner(fmt.Sprintf(" Starting BTP Bridge for %s,%s", chainA, chainB))

Expand All @@ -66,9 +66,16 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command {
data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
fmt.Println(err)
diveContext.FatalError("Starlark Run Failed", err.Error())
}
response, services, skippedInstructions, err := diveContext.GetSerializedData(data)
if err != nil {
diveContext.StopServices(services)
diveContext.FatalError("Starlark Run Failed", err.Error())

}
response := diveContext.GetSerializedData(data)

diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running")

common.WriteToFile(response)

Expand All @@ -77,10 +84,15 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command {
data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
fmt.Println(err)
diveContext.FatalError("Starlark Run Failed", err.Error())
}
response := diveContext.GetSerializedData(data)
response, services, skippedInstructions, err := diveContext.GetSerializedData(data)
if err != nil {
diveContext.StopServices(services)
diveContext.FatalError("Starlark Run Failed", err.Error())

}
diveContext.CheckInstructionSkipped(skippedInstructions, "Bridge Already Running")
common.WriteToFile(response)

} else {
Expand All @@ -91,8 +103,8 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command {
},
}

btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "Metion Name of Supported Chain")
btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "Metion Name of Supported Chain")
btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "Mention Name of Supported Chain")
btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "Mention Name of Supported Chain")
btpbridgeCmd.Flags().Bool("bridge", false, "Mention Bridge ENV")

btpbridgeCmd.MarkFlagRequired("chainA")
Expand Down
41 changes: 29 additions & 12 deletions cli/commands/chain/types/eth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package types

import (
"os"
"strings"

"github.com/hugobyte/dive/common"
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/spf13/cobra"
Expand All @@ -17,13 +20,10 @@ It establishes a connection to the Ethereum network and allows the node in execu

common.ValidateCmdArgs(args, cmd.UsageString())

data, err := RunEthNode(diveContext)
data := RunEthNode(diveContext)

if err != nil {
diveContext.FatalError("Fail to Start ETH Node", err.Error())
}
diveContext.SetSpinnerMessage("Execution Completed")
err = data.WriteDiveResponse(diveContext)
err := data.WriteDiveResponse(diveContext)
if err != nil {
diveContext.FatalError("Failed To Write To File", err.Error())
}
Expand All @@ -35,30 +35,47 @@ It establishes a connection to the Ethereum network and allows the node in execu

}

func RunEthNode(diveContext *common.DiveContext) (*common.DiveserviceResponse, error) {
diveContext.StartSpinner(" Starting ETH Node")
func RunEthNode(diveContext *common.DiveContext) *common.DiveserviceResponse {

diveContext.InitKurtosisContext()
kurtosisEnclaveContext, err := diveContext.GetEnclaveContext()

if err != nil {
return nil, err
diveContext.FatalError("Failed To Retrive Enclave Context", err.Error())
}
diveContext.StartSpinner(" Starting ETH Node")

data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveEthHardhatNodeScript, "start_eth_node", `{"args":{}}`, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
return nil, err

diveContext.FatalError("Starlark Run Failed", err.Error())

}

responseData := diveContext.GetSerializedData(data)
responseData, services, skippedInstructions, err := diveContext.GetSerializedData(data)

if err != nil {
if strings.Contains(err.Error(), "already exists") {
diveContext.StopSpinner("Eth Node Already Running")
os.Exit(0)
} else {
diveContext.StopServices(services)
diveContext.FatalError("Starlark Run Failed", err.Error())
}

}
diveContext.CheckInstructionSkipped(skippedInstructions, common.DiveEthNodeAlreadyRunning)

ethResponseData := &common.DiveserviceResponse{}

result, err := ethResponseData.Decode([]byte(responseData))

if err != nil {
return nil, err
diveContext.StopServices(services)
diveContext.FatalError("Fail to Start ETH Node", err.Error())
}

return result, nil
return result

}
29 changes: 16 additions & 13 deletions cli/commands/chain/types/hardhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ It establishes a connection to the hardhat network and allows the node in execut

common.ValidateCmdArgs(args, cmd.UsageString())

data, err := RunHardhatNode(diveContext)
data := RunHardhatNode(diveContext)

if err != nil {
diveContext.FatalError("Fail to Start Hardhat Node", err.Error())
}
diveContext.SetSpinnerMessage("Execution Completed")

err = data.WriteDiveResponse(diveContext)
err := data.WriteDiveResponse(diveContext)
if err != nil {
diveContext.FatalError("Failed To Write To File", err.Error())
}
Expand All @@ -36,32 +33,38 @@ It establishes a connection to the hardhat network and allows the node in execut

}

func RunHardhatNode(diveContext *common.DiveContext) (*common.DiveserviceResponse, error) {
func RunHardhatNode(diveContext *common.DiveContext) *common.DiveserviceResponse {

diveContext.StartSpinner(" Starting Hardhat Node")
diveContext.InitKurtosisContext()

kurtosisEnclaveContext, err := diveContext.GetEnclaveContext()

if err != nil {
return nil, err
diveContext.FatalError("Failed To Retrive Enclave Context", err.Error())
}

diveContext.StartSpinner(" Starting Hardhat Node")
data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveEthHardhatNodeScript, "start_hardhat_node", "{}", common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
return nil, err
diveContext.FatalError("Starlark Run Failed", err.Error())
}

responseData := diveContext.GetSerializedData(data)
responseData, services, skippedInstructions, err := diveContext.GetSerializedData(data)
if err != nil {
diveContext.StopServices(services)
diveContext.FatalError("Starlark Run Failed", err.Error())
}

diveContext.CheckInstructionSkipped(skippedInstructions, common.DiveHardhatNodeAlreadyRuning)
hardhatResponseData := &common.DiveserviceResponse{}

result, err := hardhatResponseData.Decode([]byte(responseData))

if err != nil {
return nil, err
diveContext.StopServices(services)
diveContext.FatalError("Failed To Unmarshall Data", err.Error())
}

return result, nil
return result

}
Loading

0 comments on commit 94aa54b

Please sign in to comment.