Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Improve error messages when unable to find bytecode #1558

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/sol-trace/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "2.0.1",
"changes": [
{
"note": "Improve error messages when unable to find matching bytecode",
"pr": 1558
}
]
},
{
"version": "2.0.0",
"changes": [
Expand Down
1 change: 1 addition & 0 deletions packages/sol-trace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 15 additions & 2 deletions packages/sol-trace/src/revert_trace_subprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 choosen 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;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/sol-tracing-utils/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
},
Expand Down
1 change: 1 addition & 0 deletions packages/sol-tracing-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 15 additions & 2 deletions packages/sol-tracing-utils/src/trace_collector.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down