Skip to content

Commit 0fed638

Browse files
authored
errors: Lop off the string part of BorshIoError (#974)
#### 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 60ace90 commit 0fed638

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

.changeset/moody-masks-drum.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@solana/rpc-types': major
3+
'@solana/errors': major
4+
---
5+
6+
`BorshIoErrors` from the RPC no longer contain an `encodedData` property. This property used to hold the underlying error from the serialization library used on the server. This message was always subject to changes in the version of that library, or changes in the choice of library itself. New versions of the server no longer throw the underlying error, so for consistency it has been removed everywhere in Kit.

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 (pre SDK 3.0 newtype style)', () => {
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/context.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ export type SolanaErrorContext = DefaultUnspecifiedErrorContextToUndefined<
395395
variant: number;
396396
};
397397
[SOLANA_ERROR__INSTRUCTION_ERROR__BORSH_IO_ERROR]: {
398-
encodedData: string;
399398
index: number;
400399
};
401400
[SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM]: {

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type InstructionError =
1010
| 'AccountNotExecutable'
1111
| 'AccountNotRentExempt'
1212
| 'ArithmeticOverflow'
13+
| 'BorshIoError' // SDKv3 has a fieldless `BorshIoError`
1314
| 'BuiltinProgramsMustConsumeComputeUnits'
1415
| 'CallDepth'
1516
| 'ComputationalBudgetExceeded'
@@ -54,7 +55,6 @@ type InstructionError =
5455
| 'UninitializedAccount'
5556
| 'UnsupportedProgramId'
5657
| 'UnsupportedSysvar'
57-
| { BorshIoError: string }
5858
| { Custom: CustomProgramError };
5959

6060
type InstructionIndex = number;

0 commit comments

Comments
 (0)