Skip to content

Add errors to declare program macro#3757

Merged
jacobcreech merged 3 commits into
otter-sec:masterfrom
cryptopapi997:feat/add-errors-to-decl-program
Jul 8, 2025
Merged

Add errors to declare program macro#3757
jacobcreech merged 3 commits into
otter-sec:masterfrom
cryptopapi997:feat/add-errors-to-decl-program

Conversation

@cryptopapi997

Copy link
Copy Markdown
Contributor

Found myself needing this, so might as well add it.

@vercel

vercel Bot commented Jun 27, 2025

Copy link
Copy Markdown

@cryptopapi997 is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@Aursen

Aursen commented Jun 28, 2025

Copy link
Copy Markdown
Contributor

@cryptopapi997 What is the purpose of this change?

@cryptopapi997

Copy link
Copy Markdown
Contributor Author

Had some client side error handling where depending on the error code I would handle the error differently. Currently this meant just copy pasting my error enum over from the program, which evidently silently broke the other day when we changed something in the errors in the program and forgot to update it in the client. This is a problem which is meant to be avoidable by having an idl that you just update once and then let changes propagate through declare_program!, but at the moment this isn't possible since the errors aren't exposed.

@Aursen

Aursen commented Jun 28, 2025

Copy link
Copy Markdown
Contributor

Got it thanks for the explanation

@Aursen Aursen added lang Minor Minor breaking change labels Jun 29, 2025
@jacobcreech jacobcreech merged commit 864ea67 into otter-sec:master Jul 8, 2025
52 of 53 checks passed
@cryptopapi997 cryptopapi997 deleted the feat/add-errors-to-decl-program branch July 17, 2025 14:50
/// Program error type definitions.
pub mod errors {

#[anchor_lang::error_code]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might make the errors field of the IDL inconsistent during generation i.e. programs that use declare_program! might get external program errors in their own IDL. This is because the errors field of the IDL is populated via the same #[error_code] macro, meaning these declarations might conflict when there are multiple declarations in the same crate.

This is also why we manually declare the program ID in our declare_program! impl instead of just using declare_id! (#3555 (comment)).

Similar issue: #3438

WilfredAlmeida pushed a commit to KartikSoneji/anchor that referenced this pull request Oct 22, 2025
* add errors to declare program macro

* changelog and docs

* cargo fmt
Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
* add errors to declare program macro

* changelog and docs

* cargo fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang Minor Minor breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants