diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 3c4db145f7..9cbf491fb7 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -829,7 +829,13 @@ func containsTx(block *types.Block, hash common.Hash) bool { // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. -func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { +func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (value interface{}, returnErr error) { + defer func() { + if r := recover(); r != nil { + value = nil + returnErr = fmt.Errorf("panic occurred: %v, could not trace tx: %s", r, hash.Hex()) + } + }() tx, blockHash, blockNumber, index, err := api.backend.GetTransaction(ctx, hash) if err != nil { return nil, err @@ -876,7 +882,13 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config * // after executing the specified block. However, if a transaction index is provided, // the trace will be conducted on the state after executing the specified transaction // within the specified block. -func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) { +func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (value interface{}, returnErr error) { + defer func() { + if r := recover(); r != nil { + value = nil + returnErr = fmt.Errorf("panic occurred: %v, could not trace tx: %s", r, args.ToTransaction().Hash().Hex()) + } + }() // Try to retrieve the specified block var ( err error @@ -955,7 +967,7 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor defer func() { if r := recover(); r != nil { value = nil - returnErr = fmt.Errorf("panic occured: %v, could not trace tx: %s", r, tx.Hash()) + returnErr = fmt.Errorf("panic occurred: %v, could not trace tx: %s", r, tx.Hash()) } }() if config == nil {