Skip to content

Commit 31a2711

Browse files
committed
errors: Lop off the string part of BorshIoError
#### Problem The `BorshIoError` variant of `InstructionError` was changed from a string to a unit variant in the Rust SDK in [this PR](anza-xyz/solana-sdk#12), but the change hasn't been reflected in Kit yet. #### Summary of changes Change the `BorshIoError` variant to lop off any string that comes back for compatibility with old and new errors emitted by the runtime. Add the new variant to the RPC error type list.
1 parent 17e3ece commit 31a2711

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

packages/errors/src/__tests__/instruction-error-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const EXPECTED_ERROR_CODES = [
5151
['ProgramFailedToCompile', 4615042],
5252
['Immutable', 4615043],
5353
['IncorrectAuthority', 4615044],
54+
['BorshIoError', 4615045],
5455
['AccountNotRentExempt', 4615046],
5556
['InvalidAccountOwner', 4615047],
5657
['ArithmeticOverflow', 4615048],
@@ -95,11 +96,10 @@ describe('getSolanaErrorFromInstructionError', () => {
9596
}),
9697
);
9798
});
98-
it('produces the correct `SolanaError` for a `BorshIoError` error', () => {
99+
it('produces the correct `SolanaError` for a `BorshIoError` error from a string', () => {
99100
const error = getSolanaErrorFromInstructionError(123, { BorshIoError: 'abc' });
100101
expect(error).toEqual(
101102
new SolanaError(SOLANA_ERROR__INSTRUCTION_ERROR__BORSH_IO_ERROR, {
102-
encodedData: 'abc',
103103
index: 123,
104104
}),
105105
);

packages/errors/src/instruction-error.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
SOLANA_ERROR__INSTRUCTION_ERROR__BORSH_IO_ERROR,
3-
SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
4-
SOLANA_ERROR__INSTRUCTION_ERROR__UNKNOWN,
5-
} from './codes';
1+
import { SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, SOLANA_ERROR__INSTRUCTION_ERROR__UNKNOWN } from './codes';
62
import { SolanaError } from './error';
73
import { getSolanaErrorFromRpcError } from './rpc-enum-errors';
84

@@ -89,11 +85,6 @@ export function getSolanaErrorFromInstructionError(
8985
code: Number(rpcErrorContext as bigint | number),
9086
index: numberIndex,
9187
};
92-
} else if (errorCode === SOLANA_ERROR__INSTRUCTION_ERROR__BORSH_IO_ERROR) {
93-
return {
94-
encodedData: rpcErrorContext as string,
95-
index: numberIndex,
96-
};
9788
}
9889
return { index: numberIndex };
9990
},

packages/rpc-types/src/transaction-error.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ type InstructionError =
5454
| 'UninitializedAccount'
5555
| 'UnsupportedProgramId'
5656
| 'UnsupportedSysvar'
57-
| { BorshIoError: string }
57+
| 'BorshIoError' // SDKv3 has a fieldless `BorshIoError`
58+
| { BorshIoError: string } // SDK pre-v3 has a newtype for `BorshIoError`
5859
| { Custom: CustomProgramError };
5960

6061
type InstructionIndex = number;

0 commit comments

Comments
 (0)