Skip to content

Commit

Permalink
Negative error codes now get decoded correctly by the production erro…
Browse files Browse the repository at this point in the history
…r decoder (#2376)

* Negative error codes now get decoded correctly by the production error decoder

* Changeset

* Oops, wrong order
  • Loading branch information
steveluscher authored Mar 23, 2024
1 parent 6135928 commit 9370133
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-items-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/errors': patch
---

Fixed a bug that prevented the production error decoder from decoding negative error codes
2 changes: 1 addition & 1 deletion packages/errors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ When your bundler sets the constant `__DEV__` to `false`, error messages will be
For instance, to recover the error text for the error with code `123`:

```shell
npx @solana/errors decode 123
npx @solana/errors decode -- 123
```

## Adding a new error
Expand Down
6 changes: 3 additions & 3 deletions packages/errors/src/__tests__/message-formatter-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('getErrorMessage', () => {
// @ts-expect-error Mock error codes don't conform to `SolanaErrorCode`
123,
);
expect(message).toBe('Solana error #123; Decode this error by running `npx @solana/errors decode 123`');
expect(message).toBe('Solana error #123; Decode this error by running `npx @solana/errors decode -- 123`');
});
it('does not call the context encoder when the error has no context', () => {
getErrorMessage(
Expand Down Expand Up @@ -55,15 +55,15 @@ describe('getErrorMessage', () => {
const context = { foo: 'bar' };
const message = getErrorMessage(123 as SolanaErrorCode, context);
expect(message).toBe(
"Solana error #123; Decode this error by running `npx @solana/errors decode 123 'ENCODED_CONTEXT'`",
"Solana error #123; Decode this error by running `npx @solana/errors decode -- 123 'ENCODED_CONTEXT'`",
);
});
it('renders no encoded context in the decoding advice when the context has no keys', async () => {
expect.assertions(1);
jest.mocked(encodeContextObject).mockReturnValue('ENCODED_CONTEXT');
const context = {};
const message = getErrorMessage(123 as SolanaErrorCode, context);
expect(message).toBe('Solana error #123; Decode this error by running `npx @solana/errors decode 123`');
expect(message).toBe('Solana error #123; Decode this error by running `npx @solana/errors decode -- 123`');
});
});
describe('in dev mode', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/errors/src/message-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getErrorMessage<TErrorCode extends SolanaErrorCode>(code: TError
if (__DEV__) {
return getHumanReadableErrorMessage(code, context);
} else {
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode ${code}`;
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode -- ${code}`;
if (Object.keys(context).length) {
/**
* DANGER: Be sure that the shell command is escaped in such a way that makes it
Expand Down

0 comments on commit 9370133

Please sign in to comment.