Skip to content

Commit

Permalink
autopilot: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Dec 18, 2023
1 parent 19ba7d0 commit 1dddbbf
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions autopilot/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ func (ap *Autopilot) Run() error {

// perform maintenance
setChanged, err := ap.c.performContractMaintenance(ctx, w)
if err != nil {
if err != nil && isErr(err, context.Canceled) {
return
} else if err != nil {
ap.logger.Errorf("contract maintenance failed, err: %v", err)
}
maintenanceSuccess := err == nil
Expand All @@ -288,8 +290,6 @@ func (ap *Autopilot) Run() error {
ap.logger.Debug("account refills loop launched")
go ap.a.refillWorkersAccountsLoop(ap.shutdownCtx)
})
} else {
ap.logger.Errorf("contract maintenance failed, err: %v", err)
}

// migration
Expand Down Expand Up @@ -376,7 +376,9 @@ func (ap *Autopilot) blockUntilConfigured(interrupt <-chan time.Time) (configure
cancel()

// if the config was not found, or we were unable to fetch it, keep blocking
if err != nil && strings.Contains(err.Error(), api.ErrAutopilotNotFound.Error()) {
if isErr(err, context.Canceled) {
return
} else if isErr(err, api.ErrAutopilotNotFound) {
once.Do(func() { ap.logger.Info("autopilot is waiting to be configured...") })
} else if err != nil {
ap.logger.Errorf("autopilot is unable to fetch its configuration from the bus, err: %v", err)
Expand Down Expand Up @@ -407,7 +409,9 @@ func (ap *Autopilot) blockUntilOnline() (online bool) {
online = len(peers) > 0
cancel()

if err != nil {
if isErr(err, context.Canceled) {
return
} else if err != nil {
ap.logger.Errorf("failed to get peers, err: %v", err)
} else if !online {
once.Do(func() { ap.logger.Info("autopilot is waiting on the bus to connect to peers...") })
Expand Down Expand Up @@ -439,7 +443,9 @@ func (ap *Autopilot) blockUntilSynced(interrupt <-chan time.Time) (synced, block
cancel()

// if an error occurred, or if we're not synced, we continue
if err != nil {
if isErr(err, context.Canceled) {
return
} else if err != nil {
ap.logger.Errorf("failed to get consensus state, err: %v", err)
} else if !synced {
once.Do(func() { ap.logger.Info("autopilot is waiting for consensus to sync...") })
Expand Down

0 comments on commit 1dddbbf

Please sign in to comment.