Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement error handling , Service stopper on Error and Improve Logging #57

Merged
merged 11 commits into from
Jul 27, 2023
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ tsconfig.tsbuildinfo
.docusaurus
.cache-loader

dist/
dist/
logs/
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