> ## Documentation Index
> Fetch the complete documentation index at: https://docs.epicentral.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> Decode RPC, transaction, validation, and onchain program errors with decodeSdkError.

`sendBuiltTransaction` and `decodeSdkError` normalize thrown simulation, RPC, and validation failures into four typed error classes.

## Error Classes

| Class | When It Is Thrown | Key Properties |
| - | - | - |
| `SdkValidationError` | A builder or preflight rejects invalid inputs before sending. | `message` |
| `SdkOptionProgramError` | The onchain option program returns a custom error code (`6000`+). | `code`, `programErrorName`, `message`, `logs` |
| `SdkTransactionError` | Transaction send or confirmation fails. | `kind` (`"blockhash_expired" \| "insufficient_sol" \| "unconfirmed" \| "transaction_failed"`), `message`, `logs` |
| `SdkRpcError` | An account is missing or an RPC transport call fails. | `kind` (`"account_not_found" \| "transport"`), `message` |

## Decoding Errors

Wrap your build and send calls in a `try`/`catch` block and pass any unknown error to `decodeSdkError`:

```ts theme={"dark"}
import {
  decodeSdkError,
  SdkOptionProgramError,
  SdkRpcError,
  SdkTransactionError,
  SdkValidationError,
} from "@epicentral/sos-sdk";

try {
  await sendBuiltTransaction({
    ...built,
    rpc,
    rpcSubscriptions,
    feePayer: signer,
    version: 1,
  });
} catch (rawError) {
  const err = decodeSdkError(rawError);

  if (err instanceof SdkOptionProgramError) {
    console.error(`Program error ${err.code} (${err.programErrorName}): ${err.message}`);
  } else if (err instanceof SdkTransactionError) {
    console.error(`Transaction error (${err.kind}): ${err.message}`);
  } else if (err instanceof SdkRpcError) {
    console.error(`RPC error (${err.kind}): ${err.message}`);
  } else if (err instanceof SdkValidationError) {
    console.error(`Validation error: ${err.message}`);
  }
}
```

## Common Program Error Codes

Onchain program errors start at `6000`. Use `err.code` and `err.programErrorName` on `SdkOptionProgramError` to handle active program errors by category:

> [accordion] Oracles and Market Data
>
> | Code | Name | Meaning |
> | - | - | - |
> | `6011` | `StaleMarketData` | Stored Historical Volatility on `MarketDataAccount` is unset or older than 6 hours (`21,600` seconds). Wait for the volatility worker to refresh `update_market_data`. |
> | `6016` | `StaleOraclePrice` | The Pyth spot price feed account is older than 20 seconds. Refresh or wait for a fresher update. |
> | `6017` | `LowOraclePriceConfidence` | The Pyth spot confidence interval exceeds 2% of the price. Wait for oracle publishers to converge. |
> | `6018` | `InvalidOracleAccount` | The spot oracle account is not owned by the Pyth receiver, fails to deserialize, or does not match `MarketDataAccount.pythFeedId`. |
> | `6019` | `VolatilityQuoteUnavailable` | Stored `MarketDataAccount.historicalVolatilityPpm` is outside the program bounds (`0` to `4,000,000` ppm). |
> | `6023` | `InvalidOraclePrice` | The decoded Pyth spot price is non-positive or rounds to zero micro-USD. |
> | `6131` | `InsufficientOracleVerification` | The Pyth price update has fewer than 3 verified router signatures. |
> | `6138` | `SpotPriceNotFromPriceFeedAccount` | Spot was not read from the underlying asset's pinned shard-0 Pyth price feed account (`pythPriceFeedAddress`). |
> | `6139` | `SellBackPriceNotNewerThanPurchase` | Closing a Long requires a Pyth spot `publish_time` more than 5 seconds after the position's last buy. Wait for the next price update. |

> [accordion] Trading, Liquidity, and Slippage
>
> | Code | Name | Meaning |
> | - | - | - |
> | `6043` | `SlippageToleranceExceeded` | Execution price moved past your buy slippage cap, Long close `minPayoutAmount`, or Short mint `maxRequiredCollateralAmount`. Re-quote and retry. |
> | `6044` | `InsufficientPoolLiquidity` | Available OMLP vault cash or pool liquidity cannot cover the requested borrow or withdrawal. |
> | `6045` | `InsufficientPoolAggregateLiquidity` | Aggregate `OptionPool` inventory is below the requested buy quantity. Check liquidity with `preflightBuyFromPoolMarketOrder`. |
> | `6046` | `InsufficientWriterPositionLiquidity` | Active Writers in remaining accounts cannot fill the requested buy quantity. Refresh pool state and rebuild. |
> | `6115` | `SeriesNotInitialized` | The `OptionAccount`, `OptionPool`, or `CollateralPool` for this Option Identity does not exist yet. Call `buildInitOptionSeriesInstruction` first. |
> | `6118` | `SelfFillOrderFullySelfFill` | A Long buy would match only the buyer's own Writer inventory. Reduce quantity or unwind the Short directly. |
> | `6144` | `WriterQueuePrefixMismatch` | Supplied Writer queue entries no longer match the head of the onchain ring. Re-fetch accounts and rebuild the transaction. |
> | `6145` | `WriterQueuePrefixIncomplete` | Supplied Writer queue entries ended before the buy or Long close completed. Rebuild from a fresh ring read. |

> [accordion] Shorts, Opening Margin, and OMLP Loans
>
> | Code | Name | Meaning |
> | - | - | - |
> | `6006` | `InsufficientCollateral` | Posted collateral does not cover the Short mint requirement or pool payout. |
> | `6054` | `InsufficientLoanCollateral` | Own collateral posted for a leveraged Short falls below the OMLP vault leverage floor. |
> | `6088` | `EscrowAccountRequired` | A Short leg sets `borrowedAmount > 0` without passing the required maker escrow accounts. |
> | `6106` | `MaintenanceBufferBreached` | Free collateral plus premium ledger falls below accrued loan debt and the maintenance buffer. |
> | `6148` | `WriterLotBelowMinimum` | The Writer's remaining Unsold Size would fall below the vault's minimum writer lot. |
> | `6161` | `StrategyLegBorrowNotFused` | A `WriterPosition` linked to a strategy must borrow with `buildBorrowFromPoolInstruction` instead of the fused mint-with-borrow instruction. |
> | `6168` | `StrategyMarginDisabled` | Multi-leg net margin (`init_strategy_margin`) is disabled on the current program. Post collateral per leg. |
> | `6171` | `OpeningMarginNotMet` | Post-mint resources and expected premium credit fall below the conservative opening margin requirement. Size own collateral with `computeMinimumOpeningOwnCollateralBaseUnits`. |

> [accordion] Expiration, Pauses, and Account Layouts
>
> | Code | Name | Meaning |
> | - | - | - |
> | `6000` | `OptionExpired` | The Option Series has passed its `expirationDate` and can no longer be traded. |
> | `6077` | `SupplyLimitExceeded` | An OMLP deposit would exceed the vault's configured supply limit. |
> | `6140` | `AccountNotConverted` | A legacy account predates the current onchain layout and must be migrated before use. |
> | `6142` | `VaultPaused` | The OMLP vault is paused for new deposits and borrowing. Withdrawals and repayments remain open. |
> | `6143` | `SeriesCreationPaused` | Initializing new Option Series is currently paused. |

> [!TIP]
>
> Inspect metadata for any program error code at runtime with `getOptionProgramErrorInfo(code)`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.