CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-ledgerhq--errors

Comprehensive error handling library for the Ledger ecosystem with unified error classes, serialization, and hardware wallet status codes

Overview
Eval results
Files

account-errors.mddocs/

Account and Balance Errors

Error classes for account management, balance validation, transaction-related operations, and delegation functionality.

Capabilities

Account Management Errors

Error classes for account setup, naming, and device association.

const AccountNameRequiredError: CustomErrorFunc;
const AccountNotSupported: CustomErrorFunc;
const WrongDeviceForAccount: CustomErrorFunc;
const NoAddressesFound: CustomErrorFunc;

Usage Examples:

import { 
  AccountNameRequiredError,
  AccountNotSupported,
  WrongDeviceForAccount,
  NoAddressesFound
} from "@ledgerhq/errors";

// Account name is required
throw new AccountNameRequiredError("Account name must be provided");

// Account type not supported
throw new AccountNotSupported("This account type is not supported for the selected currency");

// Wrong device for this account
throw new WrongDeviceForAccount("This account belongs to a different Ledger device");

// No addresses found for account
throw new NoAddressesFound("No addresses found for this account");

Balance Validation Errors

Error classes for various balance-related validation failures in transactions and operations.

const NotEnoughBalance: CustomErrorFunc;
const NotEnoughBalanceToDelegate: CustomErrorFunc;
const NotEnoughBalanceInParentAccount: CustomErrorFunc;
const NotEnoughSpendableBalance: CustomErrorFunc;
const NotEnoughBalanceBecauseDestinationNotCreated: CustomErrorFunc;

Usage Examples:

import { 
  NotEnoughBalance,
  NotEnoughBalanceToDelegate,
  NotEnoughBalanceInParentAccount,
  NotEnoughSpendableBalance,
  NotEnoughBalanceBecauseDestinationNotCreated
} from "@ledgerhq/errors";

// Insufficient balance for transaction
throw new NotEnoughBalance("Insufficient balance to complete transaction", {
  available: "0.001 BTC",
  required: "0.005 BTC"
});

// Insufficient balance for delegation
throw new NotEnoughBalanceToDelegate("Insufficient balance to delegate stake", {
  available: "100 XTZ",
  minimumRequired: "200 XTZ"
});

// Parent account has insufficient balance
throw new NotEnoughBalanceInParentAccount("Parent account does not have enough balance");

// Insufficient spendable balance (excluding locked/reserved amounts)
throw new NotEnoughSpendableBalance("Insufficient spendable balance", {
  totalBalance: "1.0 ETH",
  spendableBalance: "0.1 ETH",
  required: "0.5 ETH"
});

// Destination account needs to be created first
throw new NotEnoughBalanceBecauseDestinationNotCreated(
  "Destination account must be created with minimum balance", 
  {
    minimumRequired: "1 XRP"
  }
);

Gas and Fee Balance Errors

Error classes specific to gas fees and transaction cost validation.

const NotEnoughGas: CustomErrorFunc;
const GasLessThanEstimate: CustomErrorFunc;

Usage Examples:

import { 
  NotEnoughGas,
  GasLessThanEstimate
} from "@ledgerhq/errors";

// Insufficient gas for Ethereum transaction
throw new NotEnoughGas("Insufficient gas to complete transaction", {
  gasRequired: "21000",
  gasAvailable: "15000",
  gasPriceGwei: "20"
});

// Gas amount is less than the estimated requirement
throw new GasLessThanEstimate("Gas amount is below the estimated requirement", {
  providedGas: "15000",
  estimatedGas: "21000"
});

Delegation and Staking Errors

Error classes for cryptocurrency delegation, staking, and undelegation operations.

const RecommendUndelegation: CustomErrorFunc;
const RecommendSubAccountsToEmpty: CustomErrorFunc;

Usage Examples:

import { 
  RecommendUndelegation,
  RecommendSubAccountsToEmpty
} from "@ledgerhq/errors";

// Recommend undelegation before performing operation
throw new RecommendUndelegation("Consider undelegating before performing this operation", {
  delegatedAmount: "500 XTZ",
  validator: "tz1abc123..."
});

// Recommend emptying sub-accounts first
throw new RecommendSubAccountsToEmpty("Consider emptying sub-accounts before closing main account", {
  subAccountCount: 3,
  totalSubAccountBalance: "0.05 BTC"
});

Cryptocurrency-Specific Account Errors

Error classes for specific cryptocurrency account limitations and requirements.

const UnavailableTezosOriginatedAccountReceive: CustomErrorFunc;
const UnavailableTezosOriginatedAccountSend: CustomErrorFunc;
const CashAddrNotSupported: CustomErrorFunc;
const NotSupportedLegacyAddress: CustomErrorFunc;

Usage Examples:

import { 
  UnavailableTezosOriginatedAccountReceive,
  UnavailableTezosOriginatedAccountSend,
  CashAddrNotSupported,
  NotSupportedLegacyAddress
} from "@ledgerhq/errors";

// Tezos originated account cannot receive
throw new UnavailableTezosOriginatedAccountReceive(
  "Cannot receive funds on Tezos originated account"
);

// Tezos originated account cannot send
throw new UnavailableTezosOriginatedAccountSend(
  "Cannot send funds from Tezos originated account"
);

// Bitcoin Cash address format not supported
throw new CashAddrNotSupported("Bitcoin Cash address format is not supported");

// Legacy address format not supported
throw new NotSupportedLegacyAddress("Legacy address format is not supported for this operation");

Currency Support Errors

Error classes for cryptocurrency and currency support validation.

const CurrencyNotSupported: CustomErrorFunc;

Usage Examples:

import { CurrencyNotSupported } from "@ledgerhq/errors";

// Currency not supported by device or app
throw new CurrencyNotSupported("This cryptocurrency is not supported", {
  requestedCurrency: "DOGE",
  supportedCurrencies: ["BTC", "ETH", "XRP", "LTC"]
});

// Currency not supported for specific operation
throw new CurrencyNotSupported("Currency not supported for staking", {
  currency: "BTC",
  operation: "staking"
});

Type Definitions

type CustomErrorFunc = (
  message?: string,
  fields?: { [key: string]: any }
) => void;
tessl i tessl/npm-ledgerhq--errors@5.50.0

docs

account-errors.md

device-errors.md

index.md

network-errors.md

transport-errors.md

user-errors.md

utilities.md

validation-errors.md

tile.json