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. 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/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 { 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;