From 1cc6016f48cbb1ac3113f3b584a0cf3a83063b6d Mon Sep 17 00:00:00 2001 From: Jingfu Wang Date: Tue, 20 Sep 2022 14:19:40 -0400 Subject: [PATCH] Error handling refactor (#446) * refactor: error handling Signed-off-by: Jingfu Wang * refactor: update message Signed-off-by: Jingfu Wang Signed-off-by: Jingfu Wang --- constructor/dsl/dsl.go | 2 +- fetcher/utils.go | 4 ++-- parser/intent.go | 4 ++-- reconciler/reconciler.go | 6 +++--- storage/modules/balance_storage.go | 5 ++++- storage/modules/broadcast_storage.go | 4 ++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/constructor/dsl/dsl.go b/constructor/dsl/dsl.go index 00b2fbab..b02319c1 100644 --- a/constructor/dsl/dsl.go +++ b/constructor/dsl/dsl.go @@ -52,7 +52,7 @@ func Parse(ctx context.Context, file string) ([]*job.Workflow, *Error) { } defer func() { if err := f.Close(); err != nil { - log.Printf("%s: could not close %s\n", err.Error(), cleanedPath) + log.Printf("could not close %s: %s\n", cleanedPath, err.Error()) } }() diff --git a/fetcher/utils.go b/fetcher/utils.go index 4346c9ff..26920520 100644 --- a/fetcher/utils.go +++ b/fetcher/utils.go @@ -104,11 +104,11 @@ func tryAgain(fetchMsg string, thisBackoff *Backoff, err *Error) *Error { thisBackoff.attempts++ log.Printf( - "%s: retrying fetch for %s after %fs (prior attempts: %d)\n", - errMessage, + "retrying fetch for %s after %fs (prior attempts: %d): %s\n", fetchMsg, nextBackoff.Seconds(), thisBackoff.attempts, + errMessage, ) time.Sleep(nextBackoff) diff --git a/parser/intent.go b/parser/intent.go index 96b19822..8b70cf05 100644 --- a/parser/intent.go +++ b/parser/intent.go @@ -131,9 +131,9 @@ func (p *Parser) ExpectedOperations( if len(failedMatches) > 0 { errString += fmt.Sprintf( - "%s: found matching ops with unsuccessful status %s", - errString, + "found matching ops with unsuccessful status %s: %s", types.PrettyPrintStruct(failedMatches), + errString, ) } diff --git a/reconciler/reconciler.go b/reconciler/reconciler.go index a0b4750d..46ba1ef8 100644 --- a/reconciler/reconciler.go +++ b/reconciler/reconciler.go @@ -95,7 +95,7 @@ func (r *Reconciler) wrappedActiveEnqueue( change.Currency, BacklogFull, ); err != nil { - log.Printf("%s: reconciliation skipped handling failed\n", err.Error()) + log.Printf("reconciliation skipped handling failed: %s\n", err.Error()) } } } @@ -106,9 +106,9 @@ func (r *Reconciler) wrappedInactiveEnqueue( ) { if err := r.inactiveAccountQueue(true, accountCurrency, liveBlock, false); err != nil { log.Printf( - "%s: unable to queue account %s", - err.Error(), + "unable to queue account %s: %s", types.PrintStruct(accountCurrency), + err.Error(), ) } } diff --git a/storage/modules/balance_storage.go b/storage/modules/balance_storage.go index 8e07d89b..9261fe45 100644 --- a/storage/modules/balance_storage.go +++ b/storage/modules/balance_storage.go @@ -884,8 +884,11 @@ func (b *BalanceStorage) UpdateBalance( if bigNewVal.Sign() == -1 { return false, fmt.Errorf( - "%s is invalid: %w", + "account balance %s of currency %s for account %s at block %s is invalid: %w", newVal, + types.PrintStruct(change.Currency), + types.PrintStruct(change.Account), + types.PrintStruct(change.Block), storageErrs.ErrNegativeBalance, ) } diff --git a/storage/modules/broadcast_storage.go b/storage/modules/broadcast_storage.go index 94578e41..b07d4f8c 100644 --- a/storage/modules/broadcast_storage.go +++ b/storage/modules/broadcast_storage.go @@ -443,9 +443,9 @@ func (b *BroadcastStorage) performBroadcast( if err != nil { // Don't error on broadcast failure, retries will automatically be handled. log.Printf( - "%s: unable to broadcast transaction %s", - err.Error(), + "unable to broadcast transaction %s: %s", broadcast.TransactionIdentifier.Hash, + err.Error(), ) return nil