From 286ec5df40d3707a7a2c98d49c8d324372ed29c2 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 23 Aug 2017 13:37:18 +0200 Subject: 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 --- cmd/evm/json_logger.go | 8 ++++++-- cmd/evm/runner.go | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'cmd') diff --git a/cmd/evm/json_logger.go b/cmd/evm/json_logger.go index d61981062..2cfeaa795 100644 --- a/cmd/evm/json_logger.go +++ b/cmd/evm/json_logger.go @@ -57,11 +57,15 @@ func (l *JSONLogger) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cos } // CaptureEnd is triggered at end of execution. -func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration) error { +func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error { type endLog struct { Output string `json:"output"` GasUsed math.HexOrDecimal64 `json:"gasUsed"` Time time.Duration `json:"time"` + Err string `json:"error,omitempty"` } - return l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t}) + if err != nil { + return l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, err.Error()}) + } + return l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, ""}) } diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index ae5678110..96de0c76a 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -234,13 +234,13 @@ Gas used: %d `, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC, initialGas-leftOverGas) } if tracer != nil { - tracer.CaptureEnd(ret, initialGas-leftOverGas, execTime) + tracer.CaptureEnd(ret, initialGas-leftOverGas, execTime, err) } else { fmt.Printf("0x%x\n", ret) + if err != nil { + fmt.Printf(" error: %v\n", err) + } } - if err != nil { - fmt.Printf(" error: %v\n", err) - } return nil } -- cgit