Skip to content

Error Handling

Similarly to how error handling in viem works, every module in permissionless.js exports an accompanying error type which you can use to strongly type your catch statements.

These types come in the form of <Module>ErrorType. For example, the estimateUserOperationGas action exports a EstimateUserOperationGasErrorType type.

Unfortunately, TypeScript doesn't have an abstraction for typed exceptions, so the most pragmatic & vanilla approach would be to explicitly cast error types in the catch statement.

example.ts
import { 
    type EstimateUserOperationGasErrorType, 
    type SenderAlreadyDeployedError,
	ENTRYPOINT_ADDRESS_V07
} from 'permissionless'
import { bundlerClient } from './client'
 
try {
	const estimateResult = await bundlerClient.estimateUserOperationGas({
		userOperation,
	})
} catch (e) {
	const estimationError = e as EstimateUserOperationGasErrorType<"v0.7">
	estimationError.
any
name
const error = estimationError.walk( (e) => e instanceof SenderAlreadyDeployedError, ) if (error instanceof SenderAlreadyDeployedError) { error.
any
name
} }