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 
} from 'permissionless'
import { bundlerClient } from './client'
 
try {
	const blockNumber = await bundlerClient.estimateUserOperationGas({
		userOperation,
		entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
	})
} catch (e) {
	const estimationError = e as EstimateUserOperationGasErrorType
	estimationError.
name: "EstimateUserOperationGasError"
name
const error = estimationError.walk( (e) => e instanceof SenderAlreadyDeployedError, ) if (error instanceof SenderAlreadyDeployedError) { error.
SenderAlreadyDeployedError.name: "SenderAlreadyDeployedError"
name
} }