Add defer recovery for failed txs when tracing

This commit is contained in:
Philip Su 2024-12-11 19:02:51 -08:00
parent ad2a4cefac
commit 269b0fbc7a

View file

@ -611,12 +611,21 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
TxIndex: i,
TxHash: tx.Hash(),
}
res, err := api.traceTx(ctx, tx, msg, txctx, blockCtx, statedb, config)
if err != nil {
results[i] = &txTraceResult{TxHash: tx.Hash(), Error: err.Error()}
} else {
func() {
defer func() {
if r := recover(); r != nil {
results[i] = &txTraceResult{TxHash: tx.Hash(), Error: fmt.Sprintf("panic: %v", r)}
}
}()
res, err := api.traceTx(ctx, tx, msg, txctx, blockCtx, statedb, config)
if err != nil {
results[i] = &txTraceResult{TxHash: tx.Hash(), Error: err.Error()}
return
}
results[i] = &txTraceResult{TxHash: tx.Hash(), Result: res}
}
}()
}
return results, nil
}