Skip to content

Commit

Permalink
Merge pull request #499 from Fantom-foundation/HonzaDajc/callTracerFix
Browse files Browse the repository at this point in the history
Fix callTracer issue with undefined variable on failed transaction
  • Loading branch information
quan8 authored Aug 12, 2023
2 parents 9d9f51d + 5f750a8 commit f898378
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"runtime"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -2175,7 +2176,20 @@ func (api *PublicDebugAPI) traceTx(ctx context.Context, message evmcore.Message,
}, nil

case *tracers.Tracer:
return tracer.GetResult()
result, err := tracer.GetResult()
if err != nil && result == nil {
// Only for tracer called callTracer
if config.Tracer != nil && strings.Compare(*config.Tracer, "callTracer") == 0 {
if strings.Contains(err.Error(), "cannot read property 'toString' of undefined") {
log.Debug("error when debug with callTracer", "err", err.Error())
callTracer, _ := tracers.New(*config.Tracer, txctx)
callTracer.CaptureStart(vmenv, message.From(), *message.To(), false, message.Data(), message.Gas(), message.Value())
callTracer.CaptureEnd([]byte{}, message.Gas(), time.Duration(0), fmt.Errorf("execution reverted"))
result, err = callTracer.GetResult()
}
}
}
return result, err

default:
panic(fmt.Sprintf("bad tracer type %T", tracer))
Expand Down

0 comments on commit f898378

Please sign in to comment.