Program Errors and Logs
Surface failures and logs from on-chain programs. Results appear in the same fence: same-line // comments when short, multiline // blocks below the sample when not.
Search across all documentation pages
Surface failures and logs from on-chain programs. Results appear in the same fence: same-line // comments when short, multiline // blocks below the sample when not.
Print to program logs (expensive - keep sparse).
// msg!("amount={}", amount);Built-in program error codes.
// return Err(ProgramError::InvalidAccountData.into());Anchor require! aborts with error.
// require!(amount > 0, MyError::ZeroAmount);#[error_code] enum for typed errors.
// #[error_code] pub enum MyError { #[msg("zero")] ZeroAmount }Simulation returns logs array.
// sim.value.logsMap u32 custom codes in native programs.
// ProgramError::Custom(1)Common missing signature error.
// ProgramError::MissingRequiredSignatureAnchor constraint failures include account name.
// Error: ConstraintSeeds / ConstraintHasOneLog binary base64 data.
// sol_log_data(&[bytes])Prefer typed errors over only logs.
// Err(error!(MyError::X))Panics abort; prefer Result.
// avoid unwrap in on-chain pathsCompute budget exceeded fails tx.
// Program failed: Computational budget exceededDo not log secrets or full private keys.
// log pubkeys and amounts carefullyhas_one mismatch error.
// ConstraintHasOneAnchor events for indexers.
// emit!(MyEvent { ... })Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, Rust 1.91.1, and @solana/kit 7.0.0.
Reviewed by Chris St. John·Last updated Jul 18, 2026