Skip to content

Commit

Permalink
recover validation error pretty printing panic
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Sep 4, 2024
1 parent 17e08c4 commit 6d1d430
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions cmd/util/ledger/migrations/staged_contracts_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit 6d1d430

Please sign in to comment.