Skip to content
Docs

Core

GrayError and error handling

Stable GrayError codes for client and keystore—handle by code, not message.

Overview

All wallet SDK failures use GrayError with a stable code. Branch on code, not message text. HTTP APIs serialize the same shape.

Signature

js
import { GrayError, isGrayError } from "@gray3/core";

throw new GrayError({
  code: "invalid_argument",
  message: "chainId is required",
});

Parameters

FieldRequiredDescription
codeYes`string` — e.g. `invalid_argument`, `unauthorized`, `not_found`, `conflict`, `unsupported_capability`, `internal`
messageYes`string` — human-readable detail (may include wallet label/id)
retryableNo`boolean` — optional; usually false for client/keystore errors

Response / shape

ts
class GrayError extends Error {
  code: string;
  message: string;
  retryable?: boolean;
}

isGrayError(err): err is GrayError

Common client / keystore codes

FieldRequiredDescription
invalid_argumentNoBad params, paths, mnemonics, addresses
unauthorizedNoWrong/missing keystore PIN; locked storage
not_foundNoUnknown wallet / account id
conflictNoDuplicate mnemonic / key / address under policy
unsupported_capabilityNoWatch Monero; signPrepared UTXO/Monero; feature off allowlist
internalNoCorrupt keystore master key / unexpected failure

Usage

js
try {
  await client.wallets.importMnemonic({ mnemonic, password: pin });
} catch (err) {
  if (isGrayError(err)) {
    if (err.code === "conflict") {
      // show existing wallet from message / prior findMnemonic()
    } else if (err.code === "unauthorized") {
      // re-prompt PIN
    } else if (err.code === "unsupported_capability") {
      // hide or rewrite the flow (e.g. Monero watch)
    }
  }
  throw err;
}

Throws

Constructing GrayError does not throw. Prefer isGrayError at boundaries so other exceptions still surface.