Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions packages/errors/src/__tests__/instruction-error-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const EXPECTED_ERROR_CODES = [
['ProgramFailedToCompile', 4615042],
['Immutable', 4615043],
['IncorrectAuthority', 4615044],
['BorshIoError', 4615045],
['AccountNotRentExempt', 4615046],
['InvalidAccountOwner', 4615047],
['ArithmeticOverflow', 4615048],
Expand Down Expand Up @@ -95,11 +96,10 @@ describe('getSolanaErrorFromInstructionError', () => {
}),
);
});
it('produces the correct `SolanaError` for a `BorshIoError` error', () => {
it('produces the correct `SolanaError` for a `BorshIoError` error from a string', () => {
const error = getSolanaErrorFromInstructionError(123, { BorshIoError: 'abc' });
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change means that we need to make two tests, right: one that handles the error being { BorshIoError: 'abc' } and a second test that handles it being "BorshIoError"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it on line 54 as part of the generic test -- shouldn't that do what you're suggesting?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I dumb.

expect(error).toEqual(
new SolanaError(SOLANA_ERROR__INSTRUCTION_ERROR__BORSH_IO_ERROR, {
encodedData: 'abc',
index: 123,
}),
);
Expand Down
11 changes: 1 addition & 10 deletions packages/errors/src/instruction-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
SOLANA_ERROR__INSTRUCTION_ERROR__BORSH_IO_ERROR,
SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
SOLANA_ERROR__INSTRUCTION_ERROR__UNKNOWN,
} from './codes';
import { SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, SOLANA_ERROR__INSTRUCTION_ERROR__UNKNOWN } from './codes';
import { SolanaError } from './error';
import { getSolanaErrorFromRpcError } from './rpc-enum-errors';

Expand Down Expand Up @@ -89,11 +85,6 @@ export function getSolanaErrorFromInstructionError(
code: Number(rpcErrorContext as bigint | number),
index: numberIndex,
};
} else if (errorCode === SOLANA_ERROR__INSTRUCTION_ERROR__BORSH_IO_ERROR) {
return {
encodedData: rpcErrorContext as string,
index: numberIndex,
};
}
return { index: numberIndex };
},
Expand Down
3 changes: 2 additions & 1 deletion packages/rpc-types/src/transaction-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type InstructionError =
| 'UninitializedAccount'
| 'UnsupportedProgramId'
| 'UnsupportedSysvar'
| { BorshIoError: string }
| 'BorshIoError' // SDKv3 has a fieldless `BorshIoError`
| { BorshIoError: string } // SDK pre-v3 has a newtype for `BorshIoError`
| { Custom: CustomProgramError };

type InstructionIndex = number;
Expand Down
Loading