From d776217e307259c9fda8f153aa30fad232c84022 Mon Sep 17 00:00:00 2001 From: Mike <41407352+hunjixin@users.noreply.github.com> Date: Fri, 28 Jun 2024 06:53:59 +0800 Subject: [PATCH] fix: show bacalhau id error (#192) * fix: show bacalhau id error * fix: ignore bacalhau cli error * fix: log output errors from bacalhau id --------- Co-authored-by: James Walker --- pkg/executor/bacalhau/bacalhau.go | 16 ++++++++++++---- pkg/resourceprovider/resourceprovider.go | 10 +++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/executor/bacalhau/bacalhau.go b/pkg/executor/bacalhau/bacalhau.go index 66363165..19e35620 100644 --- a/pkg/executor/bacalhau/bacalhau.go +++ b/pkg/executor/bacalhau/bacalhau.go @@ -49,18 +49,26 @@ func (executor *BacalhauExecutor) Id() (string, error) { ) nodeIdCmd.Env = executor.bacalhauEnv - output, err := nodeIdCmd.CombinedOutput() + runOutputRaw, err := nodeIdCmd.CombinedOutput() if err != nil { - return "", fmt.Errorf("error calling get id results %s", err.Error()) + return "", fmt.Errorf("error calling get id results %s, %s", err.Error(), runOutputRaw) + } + + splitOutputs := strings.Split(string(runOutputRaw), "\n") + runOutput := splitOutputs[len(splitOutputs)-1] + outputError := strings.Join(strings.Fields(strings.Join(splitOutputs[:len(splitOutputs)-1], " ")), " ") + if outputError != "" { + // TODO: we need to figure out if errors here are fatal or not + log.Warn().Msgf("error calling bacalhau id: %s", outputError) } var idResult struct { ID string ClientID string } - err = json.Unmarshal(output, &idResult) + err = json.Unmarshal([]byte(runOutput), &idResult) if err != nil { - return "", fmt.Errorf("error unmarshalling job JSON %s", err.Error()) + return "", fmt.Errorf("error unmarshalling job JSON %s %s", err.Error(), runOutputRaw) } return idResult.ID, nil diff --git a/pkg/resourceprovider/resourceprovider.go b/pkg/resourceprovider/resourceprovider.go index 65e5201e..ee27669d 100644 --- a/pkg/resourceprovider/resourceprovider.go +++ b/pkg/resourceprovider/resourceprovider.go @@ -92,16 +92,20 @@ func NewResourceProvider( func (resourceProvider *ResourceProvider) Start(ctx context.Context, cm *system.CleanupManager) chan error { if !resourceProvider.options.Pow.DisablePow { - go resourceProvider.StartMineLoop(ctx) + if errCh := resourceProvider.StartMineLoop(ctx); errCh != nil { + return errCh + } } return resourceProvider.controller.Start(ctx, cm) } -func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) error { +func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) chan error { + errorChan := make(chan error, 1) walletAddress := resourceProvider.web3SDK.GetAddress() nodeId, err := resourceProvider.controller.executor.Id() if err != nil { - return err + errorChan <- err + return errorChan } log.Info().Msgf("Wallet %s node id %s is ready for mine", walletAddress, nodeId)