Skip to content

Commit 286ec5d

Browse files
holimankaralabe
authored andcommitted
cmd/evm, core/vm, internal/ethapi: Show error when exiting (#14985)
* cmd/evm, core/vm, internal/ethapi: Add 'err' to tracer interface CaptureEnd * cmd/evm: fix nullpointer when there is no error
1 parent f7e39a7 commit 286ec5d

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎cmd/evm/json_logger.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ func (l *JSONLogger) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cos
5757
}
5858

5959
// CaptureEnd is triggered at end of execution.
60-
func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration) error {
60+
func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
6161
type endLog struct {
6262
Output string `json:"output"`
6363
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
6464
Time time.Duration `json:"time"`
65+
Err string `json:"error,omitempty"`
6566
}
66-
return l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t})
67+
if err != nil {
68+
return l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, err.Error()})
69+
}
70+
return l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, ""})
6771
}

‎cmd/evm/runner.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ Gas used: %d
234234
`, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC, initialGas-leftOverGas)
235235
}
236236
if tracer != nil {
237-
tracer.CaptureEnd(ret, initialGas-leftOverGas, execTime)
237+
tracer.CaptureEnd(ret, initialGas-leftOverGas, execTime, err)
238238
} else {
239239
fmt.Printf("0x%x\n", ret)
240+
if err != nil {
241+
fmt.Printf(" error: %v\n", err)
242+
}
240243
}
241244

242-
if err != nil {
243-
fmt.Printf(" error: %v\n", err)
244-
}
245245
return nil
246246
}

‎core/vm/logger.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (s *StructLog) OpName() string {
8686
// if you need to retain them beyond the current call.
8787
type Tracer interface {
8888
CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error
89-
CaptureEnd(output []byte, gasUsed uint64, t time.Duration) error
89+
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error
9090
}
9191

9292
// StructLogger is an EVM state logger and implements Tracer.
@@ -183,8 +183,11 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
183183
return nil
184184
}
185185

186-
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration) error {
186+
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
187187
fmt.Printf("0x%x", output)
188+
if err != nil {
189+
fmt.Printf(" error: %v\n", err)
190+
}
188191
return nil
189192
}
190193

‎internal/ethapi/tracer.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (jst *JavascriptTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode,
346346
}
347347

348348
// CaptureEnd is called after the call finishes
349-
func (jst *JavascriptTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration) error {
349+
func (jst *JavascriptTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
350350
//TODO! @Arachnid please figure out of there's anything we can use this method for
351351
return nil
352352
}

0 commit comments

Comments
 (0)