Error Codes

Structured error codes and the SentinelError class for predictable error handling

3 min read

Error Codes

Sentinel uses structured error codes for every exception it raises. All errors are instances of SentinelError, a frozen subclass of Error.

Import

typescript
import { SentinelError, SentinelErrorCode } from '@sentinel-sdk/core';

SentinelError

typescript
class SentinelError extends Error {
  readonly code: SentinelErrorCode
  readonly details?: Readonly<Record<string, unknown>>
}

SentinelError instances are frozen on construction. The code field is always a SentinelErrorCode enum member. details carries structured context about the failure.

typescript
try {
  await sentinel.scanInput('...');
} catch (err) {
  if (err instanceof SentinelError) {
    console.log(err.code);    // 'SEN5002'
    console.log(err.message); // 'PromptGuard is not configured...'
    console.log(err.details); // { ... } | undefined
  }
}

Error Code Reference

Config Errors (SEN1xxx)

CodeEnumDescription
SEN1001INVALID_CONFIGThe provided configuration is malformed or missing required fields
SEN1002MISSING_API_KEYLLM provider API key not found in config or environment
SEN1003INVALID_POLICYPolicy configuration is invalid (e.g., negative limits)
SEN1004INVALID_RPC_ENDPOINTRPC endpoint URL is malformed or unreachable

Prompt Guard Errors (SEN2xxx)

CodeEnumDescription
SEN2001SCAN_FAILEDThe scan operation failed unexpectedly
SEN2002LLM_TIMEOUTLLM call exceeded the configured timeoutMs
SEN2003LLM_ERRORLLM API returned an error response
SEN2004RULE_LOAD_FAILEDFailed to load rule packs from disk
SEN2005RULE_PARSE_ERRORRule pack YAML could not be parsed

Execution Sandbox Errors (SEN3xxx)

CodeEnumDescription
SEN3001SIMULATION_FAILEDTransaction simulation failed unexpectedly
SEN3002RPC_ERRORSolana RPC returned an error response
SEN3003RPC_TIMEOUTRPC call exceeded the timeout
SEN3004RPC_BLOCKHASH_EXPIREDTransaction's recent blockhash has expired
SEN3005POLICY_CHECK_FAILEDPolicy enforcement encountered an internal error

Spending Tracker Errors (SEN4xxx)

CodeEnumDescription
SEN4001SPENDING_LIMIT_EXCEEDEDProposed spend would exceed configured limits
SEN4002SPENDING_TRACKER_ERRORInternal error in the spending tracker

General Errors (SEN5xxx)

CodeEnumDescription
SEN5001UNKNOWN_ERRORAn unexpected error with no matching category
SEN5002NOT_INITIALIZEDA component method was called before initialization
SEN5003ALREADY_INITIALIZEDInitialization was attempted on an already-initialized component

Error Handling Patterns

Distinguish Sentinel errors from other errors

typescript
import { SentinelError, SentinelErrorCode } from '@sentinel-sdk/core';

try {
  const result = await sentinel.evaluateTransaction(tx);
} catch (err) {
  if (err instanceof SentinelError) {
    switch (err.code) {
      case SentinelErrorCode.NOT_INITIALIZED:
        // ExecutionSandbox not configured
        break;
      case SentinelErrorCode.RPC_ERROR:
        // Solana RPC issue — retry or fallback
        break;
      default:
        // Other Sentinel error
    }
  } else {
    // Non-Sentinel error
    throw err;
  }
}

Using error codes as string values

typescript
// Error code strings are stable across versions
if (err.code === 'SEN5002') {
  // NOT_INITIALIZED
}

// Prefer enum members in TypeScript for type safety
if (err.code === SentinelErrorCode.NOT_INITIALIZED) {
  // ...
}

execute() never throws

Sentinel.execute() catches all internal errors and returns a blocked ExecutionResult. The only methods that throw SentinelError are scanInput() and evaluateTransaction(), and only for the NOT_INITIALIZED case (when the component wasn't configured).