DumpsterDumpster Docs
SDK

Error Handling

Normalize SDK, RPC, and program failures through DumpsterError and DumpsterErrorCode.

SDK

Normalize errors before you branch on them

The SDK now exposes a unified error surface. Instead of hardcoding hex codes or matching class names manually, convert the thrown error once and branch on DumpsterErrorCode.

import {
  DumpsterError,
  DumpsterErrorCode,
} from '@dumpster-cash/dumpster-sdk';

try {
  // fetch, build, or submit
} catch (error) {
  const dumpsterError = DumpsterError.fromAnchorError(error);

  switch (dumpsterError.code) {
    case DumpsterErrorCode.AccountNotFound:
      console.log('The target account does not exist on-chain.');
      break;
    case DumpsterErrorCode.BondingCurveComplete:
      console.log('Switch the user to DumpsterSwap.');
      break;
    case DumpsterErrorCode.SlippageExceeded:
      console.log('Refresh the preview and rebuild the transaction.');
      break;
    case DumpsterErrorCode.MigrationDisabled:
      console.log('Migration is currently unavailable for this token.');
      break;
    default:
      throw dumpsterError;
  }
}

Useful codes

CodeWhat it meansTypical client response
AccountNotFoundA required account was missing during fetch or build.Stop and refetch or verify the mint/pool you are using.
BondingCurveCompleteThe token is no longer tradable on the launch curve.Switch execution to DumpsterSwap.
BondingCurveNotCompleteMigration was attempted before the curve finished.Block migration until completion.
SlippageExceededThe preview moved outside the user's allowed bounds.Refresh state and rebuild the transaction.
InsufficientBalanceThe wallet does not hold enough tokens or quote to complete the action.Refetch balances and reduce size.
MigrationDisabledMigration is not currently available for the token you are targeting.Treat migration as unavailable and re-check state later.
DisabledThe requested venue or action is currently disabled.Disable that action path in your integration.
UnknownThe SDK could not confidently classify the failure.Log the full error and inspect the transaction logs.

Fetch/setup failures vs submitted-transaction failures

  • fetch/setup failures usually become AccountNotFound, TransactionBuildFailed, or Unknown
  • submitted transactions often become SlippageExceeded, Disabled, InsufficientBalance, or MigrationDisabled

The point of the normalizer is that your integration code no longer needs to care where the original error came from.

Match a single code directly

import {
  DumpsterErrorCode,
  matchesDumpsterErrorCode,
} from '@dumpster-cash/dumpster-sdk';

try {
  // submit transaction
} catch (error) {
  if (matchesDumpsterErrorCode(error, DumpsterErrorCode.SlippageExceeded)) {
    console.log('Ask the user to refresh the quote.');
  }
}

On this page