Skip to content

Commit d776217

Browse files
hunjixinwalkah
andauthored
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 <walkah@walkah.net>
1 parent 76b8fd8 commit d776217

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

pkg/executor/bacalhau/bacalhau.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,26 @@ func (executor *BacalhauExecutor) Id() (string, error) {
4949
)
5050
nodeIdCmd.Env = executor.bacalhauEnv
5151

52-
output, err := nodeIdCmd.CombinedOutput()
52+
runOutputRaw, err := nodeIdCmd.CombinedOutput()
5353
if err != nil {
54-
return "", fmt.Errorf("error calling get id results %s", err.Error())
54+
return "", fmt.Errorf("error calling get id results %s, %s", err.Error(), runOutputRaw)
55+
}
56+
57+
splitOutputs := strings.Split(string(runOutputRaw), "\n")
58+
runOutput := splitOutputs[len(splitOutputs)-1]
59+
outputError := strings.Join(strings.Fields(strings.Join(splitOutputs[:len(splitOutputs)-1], " ")), " ")
60+
if outputError != "" {
61+
// TODO: we need to figure out if errors here are fatal or not
62+
log.Warn().Msgf("error calling bacalhau id: %s", outputError)
5563
}
5664

5765
var idResult struct {
5866
ID string
5967
ClientID string
6068
}
61-
err = json.Unmarshal(output, &idResult)
69+
err = json.Unmarshal([]byte(runOutput), &idResult)
6270
if err != nil {
63-
return "", fmt.Errorf("error unmarshalling job JSON %s", err.Error())
71+
return "", fmt.Errorf("error unmarshalling job JSON %s %s", err.Error(), runOutputRaw)
6472
}
6573

6674
return idResult.ID, nil

pkg/resourceprovider/resourceprovider.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,20 @@ func NewResourceProvider(
9292

9393
func (resourceProvider *ResourceProvider) Start(ctx context.Context, cm *system.CleanupManager) chan error {
9494
if !resourceProvider.options.Pow.DisablePow {
95-
go resourceProvider.StartMineLoop(ctx)
95+
if errCh := resourceProvider.StartMineLoop(ctx); errCh != nil {
96+
return errCh
97+
}
9698
}
9799
return resourceProvider.controller.Start(ctx, cm)
98100
}
99101

100-
func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) error {
102+
func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) chan error {
103+
errorChan := make(chan error, 1)
101104
walletAddress := resourceProvider.web3SDK.GetAddress()
102105
nodeId, err := resourceProvider.controller.executor.Id()
103106
if err != nil {
104-
return err
107+
errorChan <- err
108+
return errorChan
105109
}
106110
log.Info().Msgf("Wallet %s node id %s is ready for mine", walletAddress, nodeId)
107111

0 commit comments

Comments
 (0)