From db800a60ec8a387a1c638655140a545f57a1fb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Mon, 2 Jan 2023 23:12:58 +0100 Subject: [PATCH 1/3] add a CONTRACT_NOT_DEPLOYED error handling --- lib/__tests__/getParsedEthersError.test.ts | 15 +++++++++++++++ lib/constants.ts | 2 ++ lib/utils/getTopLevelKnownError.ts | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/__tests__/getParsedEthersError.test.ts b/lib/__tests__/getParsedEthersError.test.ts index f0b50b0..cdf146c 100644 --- a/lib/__tests__/getParsedEthersError.test.ts +++ b/lib/__tests__/getParsedEthersError.test.ts @@ -287,6 +287,21 @@ describe("getParsedEthersError", () => { context: gasLimit.toString(), }); }); + it("should handle getCode call to an address without a deployed contract", () => { + const contractAddress = "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + const result = getParsedEthersError({ + code: ETHERS_ERROR_CODES.UNSUPPORTED_OPERATION, + operation: "getDeployed", + reason: "contract not deployed", + message: "contract not deployed", + contractAddress, + }); + + expect(result).toEqual({ + errorCode: RETURN_VALUE_ERROR_CODES.CONTRACT_NOT_DEPLOYED, + context: contractAddress, + }); + }); it("should handle unknown errors with a nested level error", () => { const code = "SOME INTERNAL ETHERS CODE"; const message = "Some internal Ethers error message"; diff --git a/lib/constants.ts b/lib/constants.ts index 3aff8b9..a872eab 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", + CONTRACT_NOT_DEPLOYED: "CONTRACT_NOT_DEPLOYED", 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", + UNSUPPORTED_OPERATION: "UNSUPPORTED_OPERATION", }; export const NESTED_ETHERS_ERROR_CODES = { diff --git a/lib/utils/getTopLevelKnownError.ts b/lib/utils/getTopLevelKnownError.ts index f85667a..01299ee 100644 --- a/lib/utils/getTopLevelKnownError.ts +++ b/lib/utils/getTopLevelKnownError.ts @@ -36,6 +36,16 @@ export function getTopLevelKnownError( }; } + if ( + ethersError.code === ETHERS_ERROR_CODES.UNSUPPORTED_OPERATION && + ethersError.operation === "getDeployed" && + ethersError.reason === "contract not deployed" + ) { + return { + errorCode: RETURN_VALUE_ERROR_CODES.CONTRACT_NOT_DEPLOYED, + context: ethersError.contractAddress, + }; + } const unpredictableGasLimitError = getUnpredictableGasLimitError(ethersError); if (unpredictableGasLimitError !== undefined) { return unpredictableGasLimitError; From ec0766f1546d73ed46ef5a1e6b42f237c17ee075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Mon, 2 Jan 2023 23:31:14 +0100 Subject: [PATCH 2/3] update the README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ad4323d..618c2b0 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 ` | +| `CONTRACT_NOT_DEPLOYED` | The requested address where the contrat is not deployed. | | `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. From 94c0d52a94b57473003ddbb40e4e84ca26faec9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Mon, 2 Jan 2023 23:39:22 +0100 Subject: [PATCH 3/3] update EthersError type --- lib/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/types.ts b/lib/types.ts index 61847cd..31199ca 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -18,6 +18,8 @@ export interface EthersError { }; action?: string; reason?: string; + operation?: string; + contractAddress?: string; } export interface NestedEthersError {