@solana/errors 2.0.0-experimental.b93299a → 2.0.0-experimental.e9c1b10
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/bin/cli.js +7 -0
- package/dist/cli.js +62 -0
- package/package.json +8 -7
- package/bin/cli.ts +0 -55
package/bin/cli.js
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/cli.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { Command, InvalidArgumentError } from "commander";
|
|
4
|
+
|
|
5
|
+
// package.json
|
|
6
|
+
var version = "2.0.0-development";
|
|
7
|
+
|
|
8
|
+
// src/codes.ts
|
|
9
|
+
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
10
|
+
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
11
|
+
|
|
12
|
+
// src/messages.ts
|
|
13
|
+
var SolanaErrorMessages = {
|
|
14
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses",
|
|
15
|
+
[SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]: "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/message-formatter.ts
|
|
19
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
20
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
21
|
+
const message = messageFormatString.replace(
|
|
22
|
+
/(?<!\\)\$(\w+)/g,
|
|
23
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
24
|
+
);
|
|
25
|
+
return message;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/cli.ts
|
|
29
|
+
var program = new Command();
|
|
30
|
+
program.name("@solana/errors").description("Decode Solana JavaScript errors thrown in production").version(version);
|
|
31
|
+
program.command("decode").description("Decode a `SolanaErrorCode` to a human-readable message").argument("<code>", "numeric error code to decode", (rawCode) => {
|
|
32
|
+
const code = parseInt(rawCode, 10);
|
|
33
|
+
if (isNaN(code) || `${code}` !== rawCode) {
|
|
34
|
+
throw new InvalidArgumentError("It must be an integer");
|
|
35
|
+
}
|
|
36
|
+
if (!(code in SolanaErrorMessages)) {
|
|
37
|
+
throw new InvalidArgumentError("There exists no error with that code");
|
|
38
|
+
}
|
|
39
|
+
return code;
|
|
40
|
+
}).argument(
|
|
41
|
+
"[encodedContext]",
|
|
42
|
+
"encoded context to interpolate into the error message",
|
|
43
|
+
(encodedContext) => Object.fromEntries(new URLSearchParams(encodedContext).entries())
|
|
44
|
+
).action((code, context) => {
|
|
45
|
+
const message = getHumanReadableErrorMessage(code, context);
|
|
46
|
+
console.log(`
|
|
47
|
+
${chalk.bold(
|
|
48
|
+
chalk.rgb(154, 71, 255)("[") + chalk.rgb(144, 108, 244)("D") + chalk.rgb(134, 135, 233)("e") + chalk.rgb(122, 158, 221)("c") + chalk.rgb(110, 178, 209)("o") + chalk.rgb(95, 195, 196)("d") + chalk.rgb(79, 212, 181)("e") + chalk.rgb(57, 227, 166)("d") + chalk.rgb(19, 241, 149)("]")
|
|
49
|
+
) + chalk.rgb(19, 241, 149)(" Solana error code #" + code)}
|
|
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
|
+
function run(argv) {
|
|
58
|
+
program.parse(argv);
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
run
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/errors",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.e9c1b10",
|
|
4
4
|
"description": "Throw, identify, and decode Solana JavaScript errors",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"solana",
|
|
33
33
|
"web3"
|
|
34
34
|
],
|
|
35
|
-
"bin": "./bin/cli.
|
|
35
|
+
"bin": "./bin/cli.js",
|
|
36
36
|
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"repository": {
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"engine": {
|
|
50
50
|
"node": ">=17.4"
|
|
51
51
|
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"commander": "^11.1.0",
|
|
54
|
+
"chalk": "^5.3.0"
|
|
55
|
+
},
|
|
52
56
|
"devDependencies": {
|
|
53
57
|
"@solana/eslint-config-solana": "^1.0.2",
|
|
54
58
|
"@swc/jest": "^0.2.29",
|
|
@@ -57,8 +61,6 @@
|
|
|
57
61
|
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
58
62
|
"@typescript-eslint/parser": "^6.3.0",
|
|
59
63
|
"agadoo": "^3.0.0",
|
|
60
|
-
"chalk": "^5.3.0",
|
|
61
|
-
"commander": "^11.1.0",
|
|
62
64
|
"eslint": "^8.45.0",
|
|
63
65
|
"eslint-plugin-jest": "^27.4.2",
|
|
64
66
|
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
@@ -68,10 +70,9 @@
|
|
|
68
70
|
"jest-runner-prettier": "^1.0.0",
|
|
69
71
|
"prettier": "^3.1",
|
|
70
72
|
"tsup": "^8.0.1",
|
|
71
|
-
"tsx": "^4.7.0",
|
|
72
73
|
"typescript": "^5.2.2",
|
|
73
74
|
"version-from-git": "^1.1.1",
|
|
74
|
-
"@solana/addresses": "2.0.0-experimental.
|
|
75
|
+
"@solana/addresses": "2.0.0-experimental.e9c1b10",
|
|
75
76
|
"build-scripts": "0.0.0",
|
|
76
77
|
"test-config": "0.0.0",
|
|
77
78
|
"tsconfig": "0.0.0"
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
]
|
|
86
87
|
},
|
|
87
88
|
"scripts": {
|
|
88
|
-
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
89
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts && tsup src/cli.ts --format esm",
|
|
89
90
|
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
|
|
90
91
|
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
91
92
|
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
package/bin/cli.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S tsx
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { Command, InvalidArgumentError } from 'commander';
|
|
5
|
-
|
|
6
|
-
import { version } from '../package.json';
|
|
7
|
-
import { SolanaErrorCode } from '../src/codes';
|
|
8
|
-
import { getHumanReadableErrorMessage } from '../src/message-formatter';
|
|
9
|
-
import { SolanaErrorMessages } from '../src/messages';
|
|
10
|
-
|
|
11
|
-
const program = new Command();
|
|
12
|
-
|
|
13
|
-
program.name('@solana/errors').description('Decode Solana JavaScript errors thrown in production').version(version);
|
|
14
|
-
|
|
15
|
-
program
|
|
16
|
-
.command('decode')
|
|
17
|
-
.description('Decode a `SolanaErrorCode` to a human-readable message')
|
|
18
|
-
.argument('<code>', 'numeric error code to decode', rawCode => {
|
|
19
|
-
const code = parseInt(rawCode, 10);
|
|
20
|
-
if (isNaN(code) || `${code}` !== rawCode) {
|
|
21
|
-
throw new InvalidArgumentError('It must be an integer');
|
|
22
|
-
}
|
|
23
|
-
if (!(code in SolanaErrorMessages)) {
|
|
24
|
-
throw new InvalidArgumentError('There exists no error with that code');
|
|
25
|
-
}
|
|
26
|
-
return code;
|
|
27
|
-
})
|
|
28
|
-
.argument('[encodedContext]', 'encoded context to interpolate into the error message', encodedContext =>
|
|
29
|
-
Object.fromEntries(new URLSearchParams(encodedContext).entries()),
|
|
30
|
-
)
|
|
31
|
-
.action((code: number, context) => {
|
|
32
|
-
const message = getHumanReadableErrorMessage(code as SolanaErrorCode, context);
|
|
33
|
-
console.log(`
|
|
34
|
-
${
|
|
35
|
-
chalk.bold(
|
|
36
|
-
chalk.rgb(154, 71, 255)('[') +
|
|
37
|
-
chalk.rgb(144, 108, 244)('D') +
|
|
38
|
-
chalk.rgb(134, 135, 233)('e') +
|
|
39
|
-
chalk.rgb(122, 158, 221)('c') +
|
|
40
|
-
chalk.rgb(110, 178, 209)('o') +
|
|
41
|
-
chalk.rgb(95, 195, 196)('d') +
|
|
42
|
-
chalk.rgb(79, 212, 181)('e') +
|
|
43
|
-
chalk.rgb(57, 227, 166)('d') +
|
|
44
|
-
chalk.rgb(19, 241, 149)(']'),
|
|
45
|
-
) + chalk.rgb(19, 241, 149)(' Solana error code #' + code)
|
|
46
|
-
}
|
|
47
|
-
- ${message}`);
|
|
48
|
-
if (context) {
|
|
49
|
-
console.log(`
|
|
50
|
-
${chalk.yellowBright(chalk.bold('[Context]'))}
|
|
51
|
-
${JSON.stringify(context, null, 4).split('\n').join('\n ')}`);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
program.parse();
|