diff --git a/README.md b/README.md index ad4323d..2e6f830 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Here is the complete list of returned objects: | `INSUFFICIENT_FUNDS_FOR_GAS` | `undefined` | | `MAX_PRIORITY_FEE_PER_GAS_HIGHER_THAN_MAX_FEE_PER_GAS` | `undefined ` | | `MAX_FEE_PER_GAS_LESS_THAN_BLOCK_BASE_FEE` | `undefined ` | +| `INVALID_ARGUMENT` | The reason why the argument is invalid | | `UNKNOWN_ERROR` | Some code or description of the error if available. `undefined` otherwise. | The error codes strings can be accesses via the `RETURN_VALUE_ERROR_CODES` constant that the package exports. diff --git a/lib/__tests__/getParsedEthersError.test.ts b/lib/__tests__/getParsedEthersError.test.ts index f0b50b0..f203a36 100644 --- a/lib/__tests__/getParsedEthersError.test.ts +++ b/lib/__tests__/getParsedEthersError.test.ts @@ -337,4 +337,20 @@ describe("getParsedEthersError", () => { context: undefined, }); }); + it("should handle invalid argument", () => { + const result = getParsedEthersError({ + message: + 'bad address checksum (argument="address", value="0x9999999999999999999999999999999999999999", code=INVALID_ARGUMENT, version=address/5.7.0)', + code: "INVALID_ARGUMENT", + reason: "bad address checksum", + argument: "address", + value: "0x9999999999999999999999999999999999999999", + }); + + expect(result).toEqual({ + errorCode: RETURN_VALUE_ERROR_CODES.INVALID_ARGUMENT, + context: + 'bad address checksum (argument="address", value="0x9999999999999999999999999999999999999999", code=INVALID_ARGUMENT, version=address/5.7.0)', + }); + }); }); diff --git a/lib/constants.ts b/lib/constants.ts index 3aff8b9..fa8ebfb 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -10,6 +10,7 @@ export const RETURN_VALUE_ERROR_CODES = { "MAX_PRIORITY_FEE_PER_GAS_HIGHER_THAN_MAX_FEE_PER_GAS", MAX_FEE_PER_GAS_LESS_THAN_BLOCK_BASE_FEE: "MAX_FEE_PER_GAS_LESS_THAN_BLOCK_BASE_FEE", + INVALID_ARGUMENT: "INVALID_ARGUMENT", UNKNOWN_ERROR: "UNKNOWN_ERROR", } as const; @@ -18,6 +19,7 @@ export const ETHERS_ERROR_CODES = { UNPREDICTABLE_GAS_LIMIT: "UNPREDICTABLE_GAS_LIMIT", ACTION_REJECTED: "ACTION_REJECTED", CALL_EXCEPTION: "CALL_EXCEPTION", + INVALID_ARGUMENT: "INVALID_ARGUMENT", }; export const NESTED_ETHERS_ERROR_CODES = { diff --git a/lib/types.ts b/lib/types.ts index 61847cd..a01ab18 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -18,6 +18,8 @@ export interface EthersError { }; action?: string; reason?: string; + argument?: string; + value?: string; } export interface NestedEthersError { diff --git a/lib/utils/getTopLevelKnownError.ts b/lib/utils/getTopLevelKnownError.ts index f85667a..fedbbd8 100644 --- a/lib/utils/getTopLevelKnownError.ts +++ b/lib/utils/getTopLevelKnownError.ts @@ -36,6 +36,13 @@ export function getTopLevelKnownError( }; } + if (ethersError.code === ETHERS_ERROR_CODES.INVALID_ARGUMENT) { + return { + errorCode: RETURN_VALUE_ERROR_CODES.INVALID_ARGUMENT, + context: ethersError.message, + }; + } + const unpredictableGasLimitError = getUnpredictableGasLimitError(ethersError); if (unpredictableGasLimitError !== undefined) { return unpredictableGasLimitError;