diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-03-31 23:15:38 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-03-31 23:26:25 +0800 |
commit | 4326061e35a76ebf1bd02379bfc2f1d05dddc529 (patch) | |
tree | 20df923487a30772ed30e76b9062734eea6ac9d9 /eth | |
parent | 6c670eff015223fbf9c33d8c25bd583b8c20f584 (diff) | |
download | dexon-4326061e35a76ebf1bd02379bfc2f1d05dddc529.tar.gz dexon-4326061e35a76ebf1bd02379bfc2f1d05dddc529.tar.zst dexon-4326061e35a76ebf1bd02379bfc2f1d05dddc529.zip |
eth: fix accidental nil panic on nil errors
Diffstat (limited to 'eth')
-rw-r--r-- | eth/api.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/eth/api.go b/eth/api.go index e2af0d614..4a03a0940 100644 --- a/eth/api.go +++ b/eth/api.go @@ -1531,7 +1531,7 @@ func (api *PrivateDebugAPI) TraceBlock(blockRlp []byte, config vm.Config) BlockT return BlockTraceResult{ Validated: validated, StructLogs: formatLogs(logs), - Error: err.Error(), + Error: formatError(err), } } @@ -1557,7 +1557,7 @@ func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config vm.Config) return BlockTraceResult{ Validated: validated, StructLogs: formatLogs(logs), - Error: err.Error(), + Error: formatError(err), } } @@ -1573,7 +1573,7 @@ func (api *PrivateDebugAPI) TraceBlockByHash(hash common.Hash, config vm.Config) return BlockTraceResult{ Validated: validated, StructLogs: formatLogs(logs), - Error: err.Error(), + Error: formatError(err), } } @@ -1666,7 +1666,7 @@ func formatLogs(structLogs []vm.StructLog) []structLogRes { Gas: trace.Gas, GasCost: trace.GasCost, Depth: trace.Depth, - Error: trace.Err.Error(), + Error: formatError(trace.Err), Stack: make([]string, len(trace.Stack)), Storage: make(map[string]string), } @@ -1686,6 +1686,15 @@ func formatLogs(structLogs []vm.StructLog) []structLogRes { return formattedStructLogs } +// formatError formats a Go error into either an empty string or the data content +// of the error itself. +func formatError(err error) string { + if err == nil { + return "" + } + return err.Error() +} + // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. func (s *PrivateDebugAPI) TraceTransaction(txHash common.Hash, logger vm.LogConfig) (*ExecutionResult, error) { |