Skip to content
Docs
Open app
Skip to Content

Errors

Handle Vault SDK errors by their stable code, and translate Move aborts from failed transactions.

  • @naviprotocol/vault 0.1.0
  • TypeScript

Every SDK failure throws a VaultSdkError with a stable code, a message and a details object. The message is for logs and can change; branch on code.

errors.ts
import { Transaction } from '@mysten/sui/transactions';
import { depositPTB, isVaultSdkError, type Vault } from '@naviprotocol/vault';

export async function tryDeposit(vault: Vault, owner: string, amount: string) {
  try {
    const tx = new Transaction();
    await depositPTB(tx, vault, owner, amount);
    return { ok: true as const, tx };
  } catch (error) {
    if (!isVaultSdkError(error)) throw error;
    switch (error.code) {
      case 'DEPOSIT_BELOW_MINIMUM':
      case 'DEPOSIT_CAP_EXCEEDED':
      case 'INSUFFICIENT_BALANCE':
        return { ok: false as const, reason: 'Choose a different amount', code: error.code };
      case 'VAULT_NOT_OPEN':
        return { ok: false as const, reason: 'Deposits are closed', code: error.code };
      case 'RATE_LIMITED':
      case 'API_REQUEST_FAILED':
      case 'CHAIN_QUERY_FAILED':
        return { ok: false as const, reason: 'Temporary failure, retry later', code: error.code };
      default:
        throw error;
    }
  }
}

Error codes

GroupCodesWhat to do
TemporaryRATE_LIMITED, API_REQUEST_FAILED, CHAIN_QUERY_FAILEDRetry with backoff
StateVAULT_NOT_OPEN, RECEIPT_UNAVAILABLE, SLIPPAGE_EXCEEDEDRetry after the vault or receipt state changes
InputINVALID_AMOUNT, INVALID_ARGUMENT, INVALID_REQUEST_TYPE, VAULT_NOT_FOUND, VAULT_UNSUPPORTED, INSUFFICIENT_BALANCE, DEPOSIT_BELOW_MINIMUM, DEPOSIT_CAP_EXCEEDEDFix the request
UnexpectedVAULT_CONFIG_INVALID, CHAIN_DATA_INVALID, API_RESPONSE_INVALID, UNSUPPORTED_CONFIG_VERSIONReport it

details can include vaultId, owner, amount, uncoveredShares and excludedReceipts, depending on the error.

Move aborts

A transaction that fails on-chain, for example a cancellation the operator beat to settlement, aborts with a Move code. Pass the error to parseMoveAbort to read the module and name, or to asVaultSdkError to map it to a VaultSdkError code. For example, 5022 (ERR_VAULT_NOT_NORMAL) becomes VAULT_NOT_OPEN.

The vault contract’s request rules and events are in the vault operations reference.

On this page