Back to Fhevm

Errors

sdk/js-sdk/docs/errors.md

0.13.0-03.5 KB
Original Source

Errors

When something goes wrong, the SDK throws structured errors that tell you exactly what happened and why. This page covers all the error types and the most common scenarios you'll encounter.

Error hierarchy

All SDK errors extend ErrorBase with structured metadata:

ts
class ErrorBase extends Error {
  readonly name: string;
  readonly message: string;
  readonly details?: string;
  readonly docsUrl?: string;
  readonly version?: string;
  readonly cause?: Error;
}

Error types

Base errors

ErrorDescription
InvalidTypeErrorValue does not match expected type
FheTypeErrorInvalid FHE type name or ID
AddressErrorInvalid Ethereum address format
ChecksummedAddressErrorAddress fails EIP-55 checksum validation
InvalidPropertyErrorObject property has invalid value
FetchErrorGeneric HTTP fetch failure
InternalErrorSDK internal bug (should not happen)

Domain errors

ErrorDescription
ACLErrorACL permission denied (encrypted value not allowed for user/contract)
EncryptionErrorEncryption operation failed
FhevmConfigErrorInvalid chain or runtime configuration
FhevmHandleErrorMalformed or invalid encrypted value handle
InputProofErrorInput proof validation failed
TFHEErrorTFHE WASM module error
ZkProofErrorZK proof generation failed
SignersErrorSignature verification failed (KMS or coprocessor)

Relayer errors

ErrorDescription
RelayerAbortErrorRequest aborted (e.g., via AbortController)
RelayerFetchErrorNetwork-level fetch failure
RelayerMaxRetryErrorMaximum retry attempts exceeded
RelayerStateErrorRelayer returned unexpected state
RelayerTimeoutErrorRequest timed out
RelayerResponseApiErrorRelayer returned an API-level error
RelayerResponseInputProofRejectedErrorRelayer rejected the input proof
RelayerResponseInvalidBodyErrorRelayer response body is malformed
RelayerResponseStatusErrorRelayer returned non-OK HTTP status

Common scenarios

ACL Permission Denied: The user or contract does not have permission on the ACL contract. Ensure the smart contract has called FHE.allow() or FHE.allowForDecryption().

2048-Bit Limit Exceeded: Requests are limited to 2048 total encrypted bits. Examples: 8x euint256 (2048), 64x euint32 (2048), 1024x ebool (2048).

Chain ID mismatch: All encrypted values in a single request must belong to the same chain.

Invalid Checksummed Address: All addresses must be EIP-55 checksummed. Validate with assertIsChecksummedAddress().

Relayer Timeout / Retry Exhausted: Encryption and decryption involve HTTP calls to the relayer. Check network connectivity and the relayerUrl in your chain config.

ExtraData Validation Failed: The extraData field is auto-fetched in most operations. If you're using standalone functions, pass "0x00" for standard operations.

Error handling

ts
try {
  const result = await client.publicDecrypt({ encryptedValues: handles });
} catch (error) {
  if (error instanceof ACLError) {
    // Handle permission issues
  } else if (error instanceof RelayerTimeoutError) {
    // Retry or notify user
  } else if (error instanceof FhevmHandleError) {
    // Invalid handle format
  }
  throw error;
}

All SDK errors include a cause chain — check error.cause for the underlying error when debugging relayer or RPC failures.