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.
Recommended pattern
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
| Code | What it means | Typical client response |
|---|---|---|
| AccountNotFound | A required account was missing during fetch or build. | Stop and refetch or verify the mint/pool you are using. |
| BondingCurveComplete | The token is no longer tradable on the launch curve. | Switch execution to DumpsterSwap. |
| BondingCurveNotComplete | Migration was attempted before the curve finished. | Block migration until completion. |
| SlippageExceeded | The preview moved outside the user's allowed bounds. | Refresh state and rebuild the transaction. |
| InsufficientBalance | The wallet does not hold enough tokens or quote to complete the action. | Refetch balances and reduce size. |
| MigrationDisabled | Migration is not currently available for the token you are targeting. | Treat migration as unavailable and re-check state later. |
| Disabled | The requested venue or action is currently disabled. | Disable that action path in your integration. |
| Unknown | The 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, orUnknown - submitted transactions often become
SlippageExceeded,Disabled,InsufficientBalance, orMigrationDisabled
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.');
}
}