diff --git a/src.ts/abi/abi-coder.ts b/src.ts/abi/abi-coder.ts index fd7f1d503..78ed28267 100644 --- a/src.ts/abi/abi-coder.ts +++ b/src.ts/abi/abi-coder.ts @@ -68,7 +68,11 @@ function getBuiltinCallException(action: CallExceptionAction, tx: { to?: null | const bytes = getBytes(data); data = hexlify(data); - if (bytes.length % 32 !== 4) { + if (bytes.length === 0) { + message += " (no data present; likely require(false) occurred"; + reason = "require(false)"; + + } else if (bytes.length % 32 !== 4) { message += " (could not decode reason; invalid data length)"; } else if (hexlify(bytes.slice(0, 4)) === "0x08c379a0") { @@ -83,7 +87,7 @@ function getBuiltinCallException(action: CallExceptionAction, tx: { to?: null | message += `: ${ JSON.stringify(reason) }`; } catch (error) { - message += " (could not decode reason; invalid data)"; + message += " (could not decode reason; invalid string data)"; } } else if (hexlify(bytes.slice(0, 4)) === "0x4e487b71") { @@ -98,7 +102,7 @@ function getBuiltinCallException(action: CallExceptionAction, tx: { to?: null | reason = `Panic due to ${ PanicReasons.get(code) || "UNKNOWN" }(${ code })`; message += `: ${ reason }`; } catch (error) { - message += " (could not decode panic reason)"; + message += " (could not decode panic code)"; } } else { message += " (unknown custom error)"; diff --git a/src.ts/abi/interface.ts b/src.ts/abi/interface.ts index 54abd097b..f266e9f25 100644 --- a/src.ts/abi/interface.ts +++ b/src.ts/abi/interface.ts @@ -777,17 +777,16 @@ export class Interface { const error = AbiCoder.getBuiltinCallException("call", tx, data); // Not a built-in error; try finding a custom error - if (!error.message.match(/could not decode/)) { + const customPrefix = "execution reverted (unknown custom error)"; + if (error.message.startsWith(customPrefix)) { const selector = hexlify(data.slice(0, 4)); - error.message = "execution reverted (unknown custom error)"; const ef = this.getError(selector); if (ef) { try { + const args = this.#abiCoder.decode(ef.inputs, data.slice(4)); error.revert = { - name: ef.name, - signature: ef.format(), - args: this.#abiCoder.decode(ef.inputs, data.slice(4)) + name: ef.name, signature: ef.format(), args }; error.reason = error.revert.signature; error.message = `execution reverted: ${ error.reason }` diff --git a/src.ts/utils/errors.ts b/src.ts/utils/errors.ts index 32f20410b..8ecc99b91 100644 --- a/src.ts/utils/errors.ts +++ b/src.ts/utils/errors.ts @@ -665,7 +665,7 @@ export function makeError>(me defineProperties(error, { code }); - if (info) { defineProperties(error, info); } + if (info) { Object.assign(error, info); } return error; }