diff --git a/packages/abi/src.ts/interface.ts b/packages/abi/src.ts/interface.ts index 98e4e6024..530781911 100644 --- a/packages/abi/src.ts/interface.ts +++ b/packages/abi/src.ts/interface.ts @@ -43,9 +43,9 @@ export class Indexed extends Description { } } -const BuiltinErrors: Record, reason?: boolean }> = { - "0x08c379a0": { signature: "Error(string)", inputs: [ "string" ], reason: true }, - "0x4e487b71": { signature: "Panic(uint256)", inputs: [ "uint256" ] } +const BuiltinErrors: Record, name: string, reason?: boolean }> = { + "0x08c379a0": { signature: "Error(string)", name: "Error", inputs: [ "string" ], reason: true }, + "0x4e487b71": { signature: "Panic(uint256)", name: "Panic", inputs: [ "uint256" ] } } function wrapAccessError(property: string, error: Error): Error { @@ -350,6 +350,7 @@ export class Interface { let reason: string = null; let errorArgs: Result = null; + let errorName: string = null; let errorSignature: string = null; switch (bytes.length % this._abiCoder._getWordSize()) { case 0: @@ -362,14 +363,16 @@ export class Interface { const selector = hexlify(bytes.slice(0, 4)); const builtin = BuiltinErrors[selector]; if (builtin) { - errorSignature = builtin.signature; errorArgs = this._abiCoder.decode(builtin.inputs, bytes.slice(4)); + errorName = builtin.name; + errorSignature = builtin.signature; if (builtin.reason) { reason = errorArgs[0]; } } else { try { const error = this.getError(selector); - errorSignature = error.format(); errorArgs = this._abiCoder.decode(error.inputs, bytes.slice(4)); + errorName = error.name; + errorSignature = error.format(); } catch (error) { console.log(error); } @@ -380,7 +383,7 @@ export class Interface { return logger.throwError("call revert exception", Logger.errors.CALL_EXCEPTION, { method: functionFragment.format(), - errorSignature, errorArgs, reason + errorArgs, errorName, errorSignature, reason }); } diff --git a/packages/tests/src.ts/test-contract-interface.ts b/packages/tests/src.ts/test-contract-interface.ts index 2dc24e533..8f936ac98 100644 --- a/packages/tests/src.ts/test-contract-interface.ts +++ b/packages/tests/src.ts/test-contract-interface.ts @@ -651,6 +651,7 @@ describe('Test EIP-838 Error Codes', function() { } catch (error) { assert.equal(error.code, ethers.utils.Logger.errors.CALL_EXCEPTION, "error.code"); assert.equal(error.errorSignature, "TestError1(address,uint256)", "error.errorSignature"); + assert.equal(error.errorName, "TestError1", "error.errorName"); assert.equal(error.errorArgs[0], addr, "error.errorArgs[0]"); assert.equal(error.errorArgs.addr, addr, "error.errorArgs.addr"); assert.equal(error.errorArgs[1], 42, "error.errorArgs[1]");