codama-idl / codama

Generate clients, CLIs, documentation and more from your Solana programs
MIT License
73 stars 16 forks source link

Add isProgramError helper in JS renderer #127

Closed lorisleiva closed 2 months ago

lorisleiva commented 2 months ago

This PR generates a new helper function in the JS renderer that wraps isProgramError from @solana/programs such that, the error code type is known and the program address must not be provided.

Here's an example using the system program.

// Before.
isProgramError(error, txMessage, SYSTEM_PROGRAM_ADDRESS, SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE);

// After.
isSystemError(error, txMessage, SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE);

Here's another example without passing an explicit code expectation. For it to work with isProgramError a type parameter must be provided. With the generated helper, this is no longer needed.

// Before.
isProgramError<SystemError>(error, txMessage, SYSTEM_PROGRAM_ADDRESS);

// After.
isSystemError(error, txMessage);
changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: 0d6b73ba950db38ecdf02386f7e001748b3ddb2a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ----------------------- | ----- | | @kinobi-so/renderers-js | Patch | | @kinobi-so/renderers | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR