Skip to content

program: Add custom errors#51

Merged
febo merged 3 commits into
mainfrom
febo/custom-errors
May 11, 2026
Merged

program: Add custom errors#51
febo merged 3 commits into
mainfrom
febo/custom-errors

Conversation

@febo
Copy link
Copy Markdown
Contributor

@febo febo commented May 9, 2026

Problem

There are a few places where it should be using a custom error instead of generic errors.

Solution

Add custom errors.

@lorisleiva Client generation does not seem to be exporting the errors.

@febo febo marked this pull request as draft May 9, 2026 15:05
@febo febo requested a review from lorisleiva May 9, 2026 15:05
@lorisleiva
Copy link
Copy Markdown
Member

I don't think this program is currently using Codama Macros (it may have been created before Codama Macros was implemented) so the IDL must have been written manually.

// Then we expect the transaction to fail.
const error = await t.throwsAsync(promise);
t.true(isSolanaError(error.cause, SOLANA_ERROR__INSTRUCTION_ERROR__INVALID_ACCOUNT_DATA));
t.true(isProgramMetadataError(error.cause, transactionMessage, PROGRAM_METADATA_ERROR__IMMUTABLE_METADATA_ACCOUNT));
Copy link
Copy Markdown
Contributor Author

@febo febo May 11, 2026

Choose a reason for hiding this comment

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

@lorisleiva Not sure if this is the best way to assert a custom error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is perfect!

@febo febo marked this pull request as ready for review May 11, 2026 12:56
Copy link
Copy Markdown
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

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

Perfect, thank you!

@febo febo merged commit 792d23a into main May 11, 2026
9 checks passed
@febo febo deleted the febo/custom-errors branch May 11, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants