Skip to main content

parseCypherError

Use parseCypherError to extract a structured error from any thrown value. It handles all the ways Anchor can surface program errors - direct AnchorError instances, log lines, and raw transaction simulation failures.
TypeScript
import { parseCypherError } from "@cypher-zk/sdk";

try {
  await client.actions.placeBet({ ... });
} catch (err) {
  const parsed = parseCypherError(err);
  if (parsed) {
    console.error(`[${parsed.code}] ${parsed.name}: ${parsed.msg}`);
    // e.g., "[6000] MarketNotActive: Market is not active"
  } else {
    // Non-Cypher error (network issue, etc.)
    console.error(err);
  }
}

Return type

TypeScript
interface ParsedCypherError {
  code: number;   // e.g., 6000
  name: string;   // e.g., "MarketNotActive"
  msg: string;    // e.g., "Market is not active"
}
Returns null if the thrown value is not a Cypher program error.

Error codes

All Cypher errors start at Anchor’s 6000 offset.
CodeNameMessage
6000MarketNotActiveMarket is not active
6001MarketClosedMarket is closed
6002MarketStillOpenMarket is still open for betting
6003AlreadyResolvedMarket is already resolved
6004NotResolvedMarket is not yet resolved
6005UnauthorizedResolverCaller is not the designated resolver
6006UnauthorizedAdminCaller is not the admin
6007AlreadyClaimedPosition already claimed
6008PositionLostPosition did not win - cannot claim payout
6009BetTooSmallBet amount is below the minimum
6010InsufficientVaultBalanceVault has insufficient funds
6011NoFeesToClaimNo fees available to claim
6012LiquidityTooLowPool liquidity too low
6013InvalidCloseTimeClose time is in the past or too soon
6014EmptyQuestionMarket question cannot be empty
6015QuestionTooLongQuestion exceeds 200 bytes
6016OverflowArithmetic overflow
6017InvalidOutcomeOutcome value is out of range
6018InvalidFeeRateFee rate exceeds maximum allowed
6019InvalidTreasuryInvalid treasury public key
6020BondAlreadyWithdrawnCreator bond already withdrawn
6021NotMarketCreatorCaller is not the market creator
6022MarketHasBetsCannot cancel a market with existing bets
6023ResolutionDeadlinePassedResolution deadline has passed
6024MarketNotUnresolvedMarket is not in an unresolved state
6025ResolutionDeadlineNotReachedResolution deadline has not been reached yet
6026ClaimPeriodExpiredClaim period has expired
6027RefundPeriodExpiredRefund period has expired
6028ComputationAlreadyQueuedArcium computation already queued for this position
6029AbortedComputationArcium computation was aborted
6030ComputationVerificationFailedArcium computation verification failed
6031CannotWithdrawFromUnresolvedCannot withdraw creator funds from unresolved market
6032AdminAlreadyClaimedAdmin already claimed remaining vault funds
6033WrongMarketTypeWrong market type for this instruction
6034WrongMintWrong token mint
6035NotAcceptedMintToken mint is not the accepted USDC mint
6036InvalidCategoryCategory value is out of range
6037InvalidChallengePeriodChallenge period is outside the allowed range
6038BondTooSmallBond amount is below the minimum
6039NotPendingResolutionMarket is not in PendingResolution state
6040ChallengePeriodNotElapsedChallenge period has not elapsed yet
6041ChallengePeriodElapsedChallenge period has already elapsed
6042MarketDisputedMarket is disputed - admin override required
6043MarketNotDisputedMarket is not disputed
6044UnauthorizedUserCaller is not authorized for this operation

Common patterns

Check for a specific error:
TypeScript
import { parseCypherError, CypherErrorCode } from "@cypher-zk/sdk";

const parsed = parseCypherError(err);
if (parsed?.code === CypherErrorCode.BetTooSmall) {
  showToast(`Minimum bet is $${market.minBet / 1_000_000n}`);
}
Handle in React:
TypeScript
import { usePlaceBet, parseCypherError } from "@cypher-zk/sdk/react";

const placeBet = usePlaceBet({
  onError: (err) => {
    const parsed = parseCypherError(err);
    setError(parsed?.msg ?? "Transaction failed");
  },
});