Flow Wallet Kit

Error Handling

Error handling documentation for Flow Wallet Kit iOS SDK

Error Handling

The Flow Wallet Kit for iOS implements comprehensive error handling to help developers handle and debug issues effectively.

Flow Wallet Kit provides comprehensive error handling through the FWKError enum. This documentation covers all possible errors you might encounter while using the SDK and how to handle them.

Error Categories

General Errors

ErrorDescriptionCommon Causes
noImplementFeature not implementedAttempting to use planned but unavailable functionality
emptyKeychainNo keys in keychainMissing or deleted keychain entries
emptyKeyInvalid key dataCorrupted or missing key data
emptySignKeyMissing signing keyAttempting to sign without setting up a key

Cryptographic Errors

ErrorDescriptionCommon Causes
unsupportHashAlgorithmUnsupported hash algorithmUsing non-supported hashing method
unsupportSignatureAlgorithmUnsupported signature algorithmUsing non-supported signing method
initChaChapolyFailedChaCha20-Poly1305 initialization failedEncryption setup issues
initHDWalletFailedHD wallet initialization failedInvalid entropy or seed phrase
initPrivateKeyFailedPrivate key initialization failedInvalid key data
restoreWalletFailedWallet restoration failedCorrupted backup data
invaildSignatureAlgorithmInvalid signature algorithmUnknown signing algorithm specified
invaildEVMAddressInvalid EVM addressMalformed Ethereum address

Authentication Errors

ErrorDescriptionCommon Causes
invaildPasswordInvalid passwordWrong password for decryption
invaildPrivateKeyInvalid private key formatMalformed private key data
invaildKeyStoreJSONInvalid KeyStore JSONMalformed or incomplete KeyStore file
invaildKeyStorePasswordInvalid KeyStore passwordWrong password for KeyStore
signErrorSigning operation failedTransaction signing issues
initPublicKeyFailedPublic key initialization failedKey derivation issues
failedPassSecurityCheckSecurity check failedFailed security validation

Network Errors

ErrorDescriptionCommon Causes
incorrectKeyIndexerURLInvalid key indexer URLMalformed service URL
keyIndexerRequestFailedKey indexer request failedNetwork or service issues
decodeKeyIndexerFailedKey indexer response decode failedInvalid response format

Storage Errors

ErrorDescriptionCommon Causes
loadCacheFailedCache loading failedCorrupted cache data
invaildWalletTypeInvalid wallet typeUnsupported operation for wallet type
cacheDecodeFailedCache decode failedInvalid cache data format
emptyCreatedAddressEmpty created addressAccount creation failure

Error Handling Example

Here's how to properly handle errors in your code:

do {
    let wallet = try await FlowWallet.create()
    try await wallet.sign(transaction)
} catch FWKError.emptySignKey {
    // Handle missing signing key
    print("No signing key available")
} catch FWKError.signError {
    // Handle signing failure
    print("Failed to sign transaction")
} catch {
    // Handle other errors
    print("Unexpected error: \(error)")
}

Error Codes

Each error case has a unique error code that can be accessed through the errorCode property. The error codes are based on the order of declaration in the FWKError enum.

let error = FWKError.emptySignKey
print(error.description) // Prints: "FWKError Code: 3-emptySignKey"

Best Practices

  1. Always handle specific errors: Catch and handle specific error cases that your application needs to respond to differently.
  2. Provide user feedback: Convert technical errors into user-friendly messages.
  3. Log errors: Use the error codes and descriptions for logging and debugging.
  4. Security considerations: Never expose sensitive information in error messages.

Common Error Resolution

Here are some common approaches to resolving specific errors:

  • emptyKeychain: Ensure proper key initialization and storage
  • initHDWalletFailed: Verify seed phrase or entropy input
  • signError: Check key permissions and transaction format
  • keyIndexerRequestFailed: Verify network connection and service status
  • loadCacheFailed: Clear cache and retry operation

On this page