Errors & Codes

WativeError and the WativeErrorCode union — the single typed error the library throws — with the meaning of codes such as PARAMETER_ERROR, INVALID_PRIVATE_KEY, RECORD_LOCKED, WORKSPACE_LOCKED, STORAGE_NOT_DURABLE and UNSUPPORTED_OP.

The library throws exactly one error class: WativeError. Every failure it raises — a bad argument, a locked workspace, a rejected broadcast, an out-of-range key — arrives as a WativeError carrying a machine-readable code from the WativeErrorCode union. You branch on code, not on message text, which is written for humans and may change.

The WativeError shape

WativeError extends the built-in Error, so it has the usual message, name, and stack, plus three typed fields:

WativeError
class WativeError extends Error {
  readonly code: WativeErrorCode;
  readonly cause?: unknown;
  readonly details?: Record<string, unknown>;

  constructor(code: WativeErrorCode, message: string, opts?: WativeErrorOpts);
}

interface WativeErrorOpts {
  readonly cause?: unknown;
  readonly details?: Record<string, unknown>;
}
FieldTypeMeaning
namestringAlways "WativeError".
codeWativeErrorCodeThe stable, machine-readable code. Branch on this.
messagestringA human-readable description. Not part of the contract.
causeunknownThe underlying error, when one exists (e.g. a wrapped RPC or filesystem error).
detailsRecord<string, unknown>Structured extra context — for example WEAK_PASSWORD carries details.result, the full password check result.

WativeError and the types WativeErrorCode and WativeErrorOpts are exported from wative-core.

Catching by code

Check instanceof WativeError, then switch on err.code. Because code is a typed union, a switch gives you exhaustiveness help from the compiler.

catch-by-code.ts
import { WativeError, type WativeErrorCode } from "wative-core";

try {
  // account: an unlocked Account from the workspace
  await account.importPrivateKey(pk, "evm");
} catch (err) {
  if (err instanceof WativeError) {
    switch (err.code) {
      case "INVALID_PRIVATE_KEY":
        // the key was malformed or out of range — ask the user to re-enter it
        break;
      case "WORKSPACE_LOCKED":
        await ws.unlock(password);
        break;
      default:
        console.error(`${err.code}: ${err.message}`, err.cause);
    }
  } else {
    throw err; // not from wative-core — rethrow
  }
}

Code reference

WativeErrorCode is the union of every code the library can throw. The codes are grouped below by area for readability.

Workspace, account & records

CodeMeaning
WORKSPACE_LOCKEDAn operation needs an unlocked workspace, but it is locked. Reading ws.logger, or any password-backed action after lock(), raises this.
ACCOUNT_LOCKEDThe account or address holding the key is locked. Unlock it before signing or deriving.
RECORD_LOCKEDAn encrypted record cannot be read or saved while it is locked.
RECORD_NOT_FOUNDA requested record — a network, asset, or stored id — does not exist.

Passwords & cryptography

CodeMeaning
BAD_PASSWORDThe supplied password did not decrypt the record or workspace.
WEAK_PASSWORDA password failed the password policy. details.result carries the full PasswordCheckResult. See Password Policy.
DECRYPT_FAILEDA record's ciphertext could not be decrypted — corrupt, missing, or not valid once unlocked.
ENCRYPT_FAILEDEncryption failed, for example an invalid key length or a cipher that would not initialize.
ALGORITHM_IRREVERSIBLEAn inverse operation was requested on a one-way primitive (a KDF such as Argon2 cannot decrypt).

Keys & mnemonics

CodeMeaning
INVALID_PRIVATE_KEYA private key is not well-formed for its curve — e.g. not a 32-byte hex string, or a scalar at or beyond the secp256k1 group order.
INVALID_MNEMONICA mnemonic is malformed or contains words outside the BIP-39 English wordlist.

Arguments & storage

CodeMeaning
PARAMETER_ERRORAn argument was missing, malformed, or out of range. The most common validation code.
PROVIDER_IOA storage backend read or write failed, or a provider-level I/O precondition was violated.
PERMISSION_DENIEDStorage refused access — a read-only filesystem, or storage that is unavailable.
DISK_FULLA write failed because the disk is full or a storage quota was exceeded.
STORAGE_NOT_DURABLEThe browser refused persistent storage, so a newly created workspace could be evicted and its keys lost. Prompt the user for persistence, or pass { acknowledgeEvictionRisk: true } for a disposable workspace.

Networks & RPC

CodeMeaning
UNSUPPORTED_NETWORKNo network is known for the given chainId or slug.
RPC_UNREACHABLEThe RPC endpoint could not be reached, or its reply was lost — the outcome is unknown.
RPC_REJECTEDThe endpoint was reached and refused: it answered with a JSON-RPC error object.

Transactions

CodeMeaning
TX_BUILD_FAILEDBuilding, encoding, or decoding a transaction failed.
TX_SIGN_FAILEDSigning a transaction failed.
TX_SUBMIT_FAILEDBroadcasting a transaction failed.
TX_TIMEOUTA transaction did not reach the awaited state within its timeout.
TX_DROPPEDA submitted transaction was dropped and never included (surfaced with the dropped transaction status).
TX_ABORTEDTransaction observation was aborted by the caller.

General

CodeMeaning
UNSUPPORTED_OPThe operation is not supported in this build or on this platform — an unimplemented feature, or a native binding that could not be resolved here.

Last updated on