Skip to content

Commit dab6ede

Browse files
committedApr 13, 2022
Mimic Hardhard error strings in CALL_EXCEPTION for popular matchers (#2849, #2862).

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎packages/abi/src.ts/interface.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export class Interface {
390390
let bytes = arrayify(data);
391391

392392
let reason: string = null;
393+
let message = "";
393394
let errorArgs: Result = null;
394395
let errorName: string = null;
395396
let errorSignature: string = null;
@@ -408,6 +409,11 @@ export class Interface {
408409
errorName = builtin.name;
409410
errorSignature = builtin.signature;
410411
if (builtin.reason) { reason = errorArgs[0]; }
412+
if (errorName === "Error") {
413+
message = `; VM Exception while processing transaction: reverted with reason string ${ JSON.stringify(errorArgs[0]) }`;
414+
} else if (errorName === "Panic") {
415+
message = `; VM Exception while processing transaction: reverted with panic code ${ errorArgs[0] }`;
416+
}
411417
} else {
412418
try {
413419
const error = this.getError(selector);
@@ -420,9 +426,9 @@ export class Interface {
420426
}
421427
}
422428

423-
return logger.throwError("call revert exception", Logger.errors.CALL_EXCEPTION, {
429+
return logger.throwError("call revert exception" + message, Logger.errors.CALL_EXCEPTION, {
424430
method: functionFragment.format(),
425-
errorArgs, errorName, errorSignature, reason
431+
data: hexlify(data), errorArgs, errorName, errorSignature, reason
426432
});
427433
}
428434

‎packages/providers/src.ts/json-rpc-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function checkError(method: string, error: any, params: any): any {
5757
const result = spelunk(error);
5858
if (result) { return result.data; }
5959

60-
logger.throwError("missing revert data in call exception", Logger.errors.CALL_EXCEPTION, {
60+
logger.throwError("missing revert data in call exception; Transaction reverted without a reason string", Logger.errors.CALL_EXCEPTION, {
6161
error, data: "0x"
6262
});
6363
}

0 commit comments

Comments
 (0)
Please sign in to comment.