Quasar programs express failures through typed error enums that convert toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/blueshift-gg/quasar/llms.txt
Use this file to discover all available pages before exploring further.
ProgramError::Custom(N) at the ABI boundary. The framework reserves error codes 3000–5999 for built-in QuasarError variants and leaves 6000 and above for program-specific errors defined with #[error_code].
#[error_code] — Program-Specific Errors
Annotate an enum with #[error_code] to generate From<MyError> for ProgramError and TryFrom<u32> for MyError conversions. Variants are numbered starting from their explicit discriminant (or continuing from the previous one):
.into() or the ? operator on an expression that produces Result<_, MyError>:
require!, require_eq!, require_keys_eq!
These macros provide concise early-return assertions. They evaluate to nothing on success and return an error on failure:
if !condition { return Err(error.into()); } expression and are valid in any function returning Result<_, ProgramError>.
Built-in QuasarError Variants
QuasarError is defined in quasar_lang::error and covers every constraint and validation failure the framework can produce. All variants start at code 3000:
| Variant | Code | When emitted |
|---|---|---|
AccountNotInitialized | 3000 | Account data is all zeros (discriminator check fails before any field access) |
AccountAlreadyInitialized | 3001 | #[account(init)] on an account already owned by the program |
InvalidPda | 3002 | PDA derivation does not match the expected address |
InvalidSeeds | 3003 | Seeds produce an on-curve point (not a valid PDA) or seed count exceeds 16 |
ConstraintViolation | 3004 | #[account(constraints(...))] expression evaluated to false |
HasOneMismatch | 3005 | #[account(has_one(...))] field doesn’t match the other account’s address |
InvalidDiscriminator | 3006 | Account discriminator bytes don’t match the expected value for the type |
InsufficientSpace | 3007 | Account data is too short for the declared Space |
AccountNotRentExempt | 3008 | Lamport balance is below the rent-exemption minimum |
AccountOwnedByWrongProgram | 3009 | Account owner doesn’t match the expected program |
AccountNotMutable | 3010 | #[account(mut)] on an account not passed as writable |
AccountNotSigner | 3011 | Signer account not passed with the signer flag set |
AddressMismatch | 3012 | #[account(address = ...)] expression doesn’t match the account’s key |
DynamicFieldTooLong | 3013 | A PodString or PodVec field exceeds its declared maximum length |
CompactWriterFieldNotSet | 3014 | set_inner committed before every compact field was written |
RemainingAccountsOverflow | 3015 | More remaining accounts than the iterator buffer can hold |
RemainingAccountDuplicate | 3016 | A duplicate remaining-account entry could not be resolved |
MissingReturnData | 3017 | CPI completed without setting return data (invoke_with_return path) |
ReturnDataFromWrongProgram | 3018 | Return data was set by a different program than the one invoked |
InvalidReturnData | 3019 | Return data length doesn’t match the expected fixed-size layout |
ProgramError vs QuasarError
Both QuasarError and user #[error_code] enums convert to ProgramError::Custom(N) via From. The reverse conversion (TryFrom<u32>) is also generated so that client code can recover the typed variant from a transaction error:
ProgramError variants (not Custom) occupy codes 0–29. Quasar’s QuasarError range starts at 3000, leaving codes 30–2999 unused. User #[error_code] enums conventionally start at 6000 to match Anchor’s offset and leave room if the framework adds more built-in errors.
Code range 0–29
Solana built-in
ProgramError variants (e.g. MissingRequiredSignature, InsufficientFunds, AccountBorrowFailed)Code range 3000–5999
Quasar built-in
QuasarError variants — framework constraint failuresCode range 6000+
User-defined
#[error_code] variants — program-specific business logic errorsConvention
Start your
#[error_code] enum at 6000 explicitly. Do not overlap with the 3000–5999 range reserved for Quasar.Complete Error Example
A typical program defines its errors in a dedicatederrors.rs module and imports it in lib.rs:
Doc comments on
#[error_code] variants are captured in the program’s IDL. Add /// comments to every variant so that client SDK consumers get human-readable error messages without having to look up numeric codes.