diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-30 20:55:58 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-30 21:12:31 +0800 |
commit | ea5e78b217fdb43c50be13a80417e77ff06c970e (patch) | |
tree | 343aa3de79a6420c6a125a6f5021b45a556ca3cc | |
parent | c9a7ef18dc75675bb1880734ce786ba126359ae6 (diff) | |
download | dexon-0x-contracts-ea5e78b217fdb43c50be13a80417e77ff06c970e.tar.gz dexon-0x-contracts-ea5e78b217fdb43c50be13a80417e77ff06c970e.tar.zst dexon-0x-contracts-ea5e78b217fdb43c50be13a80417e77ff06c970e.zip |
Improve error messages when unable to find bytecode
-rw-r--r-- | packages/sol-trace/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/sol-trace/package.json | 1 | ||||
-rw-r--r-- | packages/sol-trace/src/revert_trace_subprovider.ts | 17 | ||||
-rw-r--r-- | packages/sol-tracing-utils/CHANGELOG.json | 4 | ||||
-rw-r--r-- | packages/sol-tracing-utils/package.json | 1 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/trace_collector.ts | 17 |
6 files changed, 45 insertions, 4 deletions
diff --git a/packages/sol-trace/CHANGELOG.json b/packages/sol-trace/CHANGELOG.json index 550ca2feb..b633b3d21 100644 --- a/packages/sol-trace/CHANGELOG.json +++ b/packages/sol-trace/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.0.1", + "changes": [ + { + "note": "Improve error messages when unable to find matching bytecode", + "pr": 1558 + } + ] + }, + { "version": "2.0.0", "changes": [ { diff --git a/packages/sol-trace/package.json b/packages/sol-trace/package.json index 2aedf7ebc..25e81a82a 100644 --- a/packages/sol-trace/package.json +++ b/packages/sol-trace/package.json @@ -32,6 +32,7 @@ "@0x/sol-tracing-utils": "^4.0.1", "@0x/subproviders": "^2.1.11", "@0x/typescript-typings": "^3.0.8", + "chalk": "^2.3.0", "ethereum-types": "^1.1.6", "ethereumjs-util": "^5.1.1", "lodash": "^4.17.5", diff --git a/packages/sol-trace/src/revert_trace_subprovider.ts b/packages/sol-trace/src/revert_trace_subprovider.ts index 046dad812..899a92814 100644 --- a/packages/sol-trace/src/revert_trace_subprovider.ts +++ b/packages/sol-trace/src/revert_trace_subprovider.ts @@ -11,6 +11,7 @@ import { TraceCollectionSubprovider, utils, } from '@0x/sol-tracing-utils'; +import chalk from 'chalk'; import { stripHexPrefix } from 'ethereumjs-util'; import * as _ from 'lodash'; import { getLogger, levels, Logger } from 'loglevel'; @@ -71,9 +72,21 @@ export class RevertTraceSubprovider extends TraceCollectionSubprovider { const bytecode = await this._web3Wrapper.getContractCodeAsync(evmCallStackEntry.address); const contractData = utils.getContractDataIfExists(this._contractsData, bytecode); if (_.isUndefined(contractData)) { + const shortenHex = (hex: string) => { + /** + * Length chooses so that both error messages are of the same length + * and it's enough data to figure out which artifact has a problem. + */ + const length = 18; + return `${hex.substr(0, length + 2)}...${hex.substr(hex.length - length, length)}`; + }; const errMsg = isContractCreation - ? `Unknown contract creation transaction` - : `Transaction to an unknown address: ${evmCallStackEntry.address}`; + ? `Unable to find matching bytecode for contract creation ${chalk.bold( + shortenHex(bytecode), + )}, please check your artifacts. Ignoring...` + : `Unable to find matching bytecode for contract address ${chalk.bold( + evmCallStackEntry.address, + )}, please check your artifacts. Ignoring...`; this._logger.warn(errMsg); continue; } diff --git a/packages/sol-tracing-utils/CHANGELOG.json b/packages/sol-tracing-utils/CHANGELOG.json index 024e896da..89a5b6876 100644 --- a/packages/sol-tracing-utils/CHANGELOG.json +++ b/packages/sol-tracing-utils/CHANGELOG.json @@ -21,6 +21,10 @@ { "note": "Fix the bug in `ASTVisitor` causing the 'cannot read property `range` of `null`' error", "pr": 1557 + }, + { + "note": "Improve error messages when unable to find matching bytecode", + "pr": 1558 } ] }, diff --git a/packages/sol-tracing-utils/package.json b/packages/sol-tracing-utils/package.json index 4b0fff222..929c73b84 100644 --- a/packages/sol-tracing-utils/package.json +++ b/packages/sol-tracing-utils/package.json @@ -53,6 +53,7 @@ "ethereum-types": "^1.1.6", "ethereumjs-util": "^5.1.1", "glob": "^7.1.2", + "chalk": "^2.3.0", "istanbul": "^0.4.5", "lodash": "^4.17.5", "loglevel": "^1.6.1", diff --git a/packages/sol-tracing-utils/src/trace_collector.ts b/packages/sol-tracing-utils/src/trace_collector.ts index f5dde8762..2a1f15b83 100644 --- a/packages/sol-tracing-utils/src/trace_collector.ts +++ b/packages/sol-tracing-utils/src/trace_collector.ts @@ -1,4 +1,5 @@ import { promisify } from '@0x/utils'; +import chalk from 'chalk'; import { stripHexPrefix } from 'ethereumjs-util'; import * as fs from 'fs'; import { Collector } from 'istanbul'; @@ -71,9 +72,21 @@ export class TraceCollector { : (traceInfo as TraceInfoExistingContract).runtimeBytecode; const contractData = utils.getContractDataIfExists(this._contractsData, bytecode); if (_.isUndefined(contractData)) { + const shortenHex = (hex: string) => { + /** + * Length chooses so that both error messages are of the same length + * and it's enough data to figure out which artifact has a problem. + */ + const length = 18; + return `${hex.substr(0, length + 2)}...${hex.substr(hex.length - length, length)}`; + }; const errMsg = isContractCreation - ? `Unknown contract creation transaction` - : `Transaction to an unknown address: ${traceInfo.address}`; + ? `Unable to find matching bytecode for contract creation ${chalk.bold( + shortenHex(bytecode), + )}, please check your artifacts. Ignoring...` + : `Unable to find matching bytecode for contract address ${chalk.bold( + traceInfo.address, + )}, please check your artifacts. Ignoring...`; this._logger.warn(errMsg); return; } |