8000 bugfix: custom error code parser in ProgramError by kAsky53 · Pull Request #3625 · solana-foundation/anchor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

bugfix: custom error code parser in ProgramError #3625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The minor version will be incremented upon a breaking change and the patch versi
### Fixes

- cli, docker: Replace `backpackapp/build` Docker image with `solanafoundation/anchor` ([#3619](https://github.com/coral-xyz/anchor/pull/3619)).
- ts: Update custom error code parser in `ProgramError` ([#3625](https://github.com/coral-xyz/anchor/pull/3625)).

### Breaking

Expand Down
6 changes: 3 additions & 3 deletions ts/packages/anchor/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ export class ProgramError extends Error {
let unparsedErrorCode: string;
if (errString.includes("custom program error:")) {
let components = errString.split("custom program error: ");
if (components.length !== 2) {
return null;
} else {
if (components.length > 2) {

Choose a reason for hiding this comment

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

This isn't a proper fix, since components[1] doesn't contain just the error code—it includes more content, so trying to parse it as an integer will fail.

Copy link
Contributor Author
@kAsky53 kAsky53 Apr 2, 2025

Choose a reason for hiding this comment

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

@fantasyup parseInt() will parse it correctly though.

> parseInt('0x1771 [x.dsfjsfha; 1231]%@5')
6001
> parseInt('0x1771. Logs: [  "Program rev31KMq4qzt1y1iw926p694MHVVWT57caQrsHLFA4x invoke [1]",')
6001

unparsedErrorCode = components[1];
} else {
return null;
}
} else {
const matches = errString.match(/"Custom":([0-9]+)}/g);
Expand Down
0