Mimic Hardhard error strings in CALL_EXCEPTION for popular matchers (#2849, #2862).

This commit is contained in:
Richard Moore 2022-04-12 23:54:39 -04:00
parent 1f6c0ab281
commit dab6ede226
2 changed files with 9 additions and 3 deletions

@ -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;
@ -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);
@ -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
});
}

@ -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"
});
}