Skip to content

Commit

Permalink
Mimic Hardhard error strings in CALL_EXCEPTION for popular matchers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 13, 2022
1 parent 1f6c0ab commit dab6ede
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/abi/src.ts/interface.ts
Expand Up @@ -390,6 +390,7 @@ export class Interface {
let bytes = arrayify(data);

let reason: string = null;
let message = "";
let errorArgs: Result = null;
let errorName: string = null;
let errorSignature: string = null;
Expand All @@ -408,6 +409,11 @@ export class Interface {
errorName = builtin.name;
errorSignature = builtin.signature;
if (builtin.reason) { reason = errorArgs[0]; }
if (errorName === "Error") {
message = `; VM Exception while processing transaction: reverted with reason string ${ JSON.stringify(errorArgs[0]) }`;
} else if (errorName === "Panic") {
message = `; VM Exception while processing transaction: reverted with panic code ${ errorArgs[0] }`;
}
} else {
try {
const error = this.getError(selector);
Expand All @@ -420,9 +426,9 @@ export class Interface {
}
}

return logger.throwError("call revert exception", Logger.errors.CALL_EXCEPTION, {
return logger.throwError("call revert exception" + message, Logger.errors.CALL_EXCEPTION, {
method: functionFragment.format(),
errorArgs, errorName, errorSignature, reason
data: hexlify(data), errorArgs, errorName, errorSignature, reason
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src.ts/json-rpc-provider.ts
Expand Up @@ -57,7 +57,7 @@ function checkError(method: string, error: any, params: any): any {
const result = spelunk(error);
if (result) { return result.data; }

logger.throwError("missing revert data in call exception", Logger.errors.CALL_EXCEPTION, {
logger.throwError("missing revert data in call exception; Transaction reverted without a reason string", Logger.errors.CALL_EXCEPTION, {
error, data: "0x"
});
}
Expand Down

0 comments on commit dab6ede

Please sign in to comment.