From 6d1d4302d65ae6b0863da03673196c5de7466bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 4 Sep 2024 08:45:02 -0700 Subject: [PATCH] recover validation error pretty printing panic --- .../migrations/staged_contracts_migration.go | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/cmd/util/ledger/migrations/staged_contracts_migration.go b/cmd/util/ledger/migrations/staged_contracts_migration.go index 54725538726..3e9e4329417 100644 --- a/cmd/util/ledger/migrations/staged_contracts_migration.go +++ b/cmd/util/ledger/migrations/staged_contracts_migration.go @@ -480,21 +480,30 @@ func (m *StagedContractsMigration) MigrateAccount( ) } if err != nil { - var builder strings.Builder - errorPrinter := pretty.NewErrorPrettyPrinter(&builder, false) - - location := common.AddressLocation{ - Name: name, - Address: address, - } - printErr := errorPrinter.PrettyPrintError(err, location, m.contractsByLocation) - var errorDetails string - if printErr == nil { - errorDetails = builder.String() - } else { - errorDetails = err.Error() - } + + (func() { + defer func() { + if r := recover(); r != nil { + errorDetails = fmt.Sprintf("failed to pretty print error, panic: %v", r) + } + }() + + var builder strings.Builder + errorPrinter := pretty.NewErrorPrettyPrinter(&builder, false) + + location := common.AddressLocation{ + Name: name, + Address: address, + } + printErr := errorPrinter.PrettyPrintError(err, location, m.contractsByLocation) + + if printErr == nil { + errorDetails = builder.String() + } else { + errorDetails = err.Error() + } + })() if m.verboseErrorOutput { m.log.Error().