Skip to main content

Errors

ErrorWhenFields
AnvilConfigurationErrorinvalid value, conflict, unmet dependency, missing host fileflag, relatedFlags
AnvilTestClientConfigurationErrorinvalid test client setting, or one that contradicts the anvil options (before start); extends AnvilConfigurationErrorsetting, flag, relatedFlags
AnvilStartupErroranvil exited / not ready / Docker failure / default account not resolvablecommand, logs, cause
AnvilTestClientErrorruntime misuse or failurecode, cause
AnvilTransactionRevertedErrorconfirm() / confirmTransaction() of a reverted transaction; extends AnvilTestClientErrorcode, hash, receipt, reason

AnvilTestClientError codes​

Generated from ANVIL_TEST_CLIENT_ERROR_CODES (type AnvilTestClientErrorCode):

codeMeaning
CONTAINER_STOPPEDthe node was stopped; the client can no longer be used
SNAPSHOT_NOT_FOUNDevm_revert target does not exist (already reverted, or cleared by reset / loadState)
NOT_STARTEDuseAnvil() handle used before beforeAll started the node
TEST_HOOKS_UNAVAILABLEuseAnvil() found no beforeAll / afterAll hooks
ACCOUNT_UNAVAILABLEthe configured default account could not be resolved on the node
TRANSACTION_REVERTEDa transaction was mined but reverted
CHEAT_FAILEDa step of an AnvilCheats chain failed
CHEATS_ALREADY_RUNan AnvilCheats chain was extended after it had run
const anvil = await new AnvilContainer().start();
const client = anvil.testClient;
await anvil.stop();

expect(anvil.isStopped).toBe(true);
const error = await client.getBlockNumber().catch((e: unknown) => e);
expect(error).toBeInstanceOf(AnvilTestClientError);
expect((error as AnvilTestClientError).code).toBe("CONTAINER_STOPPED");

Tested in examples/test/e2e/lifecycle.e2e.test.ts:66

viem's own errors (reverts, RPC errors) are thrown as they are: match them by name, not instanceof (why).