@solana/errors 6.3.1 → 6.3.2-canary-20260313112147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1 -1
- package/package.json +3 -2
- package/src/cli.ts +60 -0
- package/src/codes.ts +682 -0
- package/src/context.ts +862 -0
- package/src/error.ts +148 -0
- package/src/index.ts +72 -0
- package/src/instruction-error.ts +96 -0
- package/src/json-rpc-error.ts +162 -0
- package/src/message-formatter.ts +115 -0
- package/src/messages.ts +791 -0
- package/src/rpc-enum-errors.ts +53 -0
- package/src/simulation-errors.ts +47 -0
- package/src/stack-trace.ts +5 -0
- package/src/transaction-error.ts +94 -0
package/dist/cli.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/errors",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.2-canary-20260313112147",
|
|
4
4
|
"description": "Throw, identify, and decode Solana JavaScript errors",
|
|
5
5
|
"homepage": "https://www.solanakit.com/api#solanaerrors",
|
|
6
6
|
"exports": {
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"types": "./dist/types/index.d.ts",
|
|
34
34
|
"type": "commonjs",
|
|
35
35
|
"files": [
|
|
36
|
-
"./dist/"
|
|
36
|
+
"./dist/",
|
|
37
|
+
"./src/"
|
|
37
38
|
],
|
|
38
39
|
"sideEffects": false,
|
|
39
40
|
"keywords": [
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Command, InvalidArgumentError } from 'commander';
|
|
3
|
+
|
|
4
|
+
import { version } from '../package.json';
|
|
5
|
+
import { SolanaErrorCode } from './codes';
|
|
6
|
+
import { decodeEncodedContext } from './context';
|
|
7
|
+
import { getHumanReadableErrorMessage } from './message-formatter';
|
|
8
|
+
import { SolanaErrorMessages } from './messages';
|
|
9
|
+
|
|
10
|
+
const program = new Command();
|
|
11
|
+
|
|
12
|
+
program.name('@solana/errors').description('Decode Solana JavaScript errors thrown in production').version(version);
|
|
13
|
+
|
|
14
|
+
program
|
|
15
|
+
.command('decode')
|
|
16
|
+
.description('Decode a `SolanaErrorCode` to a human-readable message')
|
|
17
|
+
.argument('<code>', 'numeric error code to decode', rawCode => {
|
|
18
|
+
const code = parseInt(rawCode, 10);
|
|
19
|
+
if (isNaN(code) || `${code}` !== rawCode) {
|
|
20
|
+
throw new InvalidArgumentError('It must be an integer');
|
|
21
|
+
}
|
|
22
|
+
if (!(code in SolanaErrorMessages)) {
|
|
23
|
+
throw new InvalidArgumentError('There exists no error with that code');
|
|
24
|
+
}
|
|
25
|
+
return code;
|
|
26
|
+
})
|
|
27
|
+
.argument('[encodedContext]', 'encoded context to interpolate into the error message', encodedContext => {
|
|
28
|
+
try {
|
|
29
|
+
return decodeEncodedContext(encodedContext);
|
|
30
|
+
} catch {
|
|
31
|
+
throw new InvalidArgumentError('Encoded context malformed');
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
.action((code: number, context: object) => {
|
|
35
|
+
const message = getHumanReadableErrorMessage(code as SolanaErrorCode, context);
|
|
36
|
+
console.log(`
|
|
37
|
+
${
|
|
38
|
+
chalk.bold(
|
|
39
|
+
chalk.rgb(154, 71, 255)('[') +
|
|
40
|
+
chalk.rgb(144, 108, 244)('D') +
|
|
41
|
+
chalk.rgb(134, 135, 233)('e') +
|
|
42
|
+
chalk.rgb(122, 158, 221)('c') +
|
|
43
|
+
chalk.rgb(110, 178, 209)('o') +
|
|
44
|
+
chalk.rgb(95, 195, 196)('d') +
|
|
45
|
+
chalk.rgb(79, 212, 181)('e') +
|
|
46
|
+
chalk.rgb(57, 227, 166)('d') +
|
|
47
|
+
chalk.rgb(19, 241, 149)(']'),
|
|
48
|
+
) + chalk.rgb(19, 241, 149)(' Solana error code #' + code)
|
|
49
|
+
}
|
|
50
|
+
- ${message}`);
|
|
51
|
+
if (context) {
|
|
52
|
+
console.log(`
|
|
53
|
+
${chalk.yellowBright(chalk.bold('[Context]'))}
|
|
54
|
+
${JSON.stringify(context, null, 4).split('\n').join('\n ')}`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export function run(argv: readonly string[]) {
|
|
59
|
+
program.parse(argv);
|
|
60
|
+
}
|