Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions lib/__tests__/getParsedEthersError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface EthersError {
};
action?: string;
reason?: string;
operation?: string;
contractAddress?: string;
}

export interface NestedEthersError {
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/getTopLevelKnownError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down