@solana/errors 2.0.0-experimental.021706b
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/LICENSE +20 -0
- package/README.md +90 -0
- package/bin/cli.js +7 -0
- package/dist/cli.js +72 -0
- package/dist/index.browser.cjs +113 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +103 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.native.js +103 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +113 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +103 -0
- package/dist/index.node.js.map +1 -0
- package/dist/types/codes.d.ts +32 -0
- package/dist/types/codes.d.ts.map +1 -0
- package/dist/types/context.d.ts +39 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/error.d.ts +14 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/message-formatter.d.ts +4 -0
- package/dist/types/message-formatter.d.ts.map +1 -0
- package/dist/types/messages.d.ts +12 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2023 Solana Labs, Inc
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
[![npm][npm-image]][npm-url]
|
|
2
|
+
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
3
|
+
[![semantic-release][semantic-release-image]][semantic-release-url]
|
|
4
|
+
<br />
|
|
5
|
+
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
|
6
|
+
|
|
7
|
+
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
8
|
+
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
9
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/errors/experimental.svg?style=flat
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/errors/experimental.svg?style=flat
|
|
11
|
+
[npm-url]: https://www.npmjs.com/package/@solana/errors/v/experimental
|
|
12
|
+
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
13
|
+
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
14
|
+
|
|
15
|
+
# @solana/errors
|
|
16
|
+
|
|
17
|
+
This package brings together every error message across all Solana JavaScript modules.
|
|
18
|
+
|
|
19
|
+
## Reading error messages
|
|
20
|
+
|
|
21
|
+
### In development mode
|
|
22
|
+
|
|
23
|
+
When your bundler sets the constant `__DEV__` to `true`, every error message will be included in the bundle. As such, you will be able to read them in plain language wherever they appear.
|
|
24
|
+
|
|
25
|
+
> [!WARNING]
|
|
26
|
+
> The size of your JavaScript bundle will increase significantly with the inclusion of every error message in development mode. Be sure to build your bundle with `__DEV__` set to `false` when you go to production.
|
|
27
|
+
|
|
28
|
+
### In production mode
|
|
29
|
+
|
|
30
|
+
When your bundler sets the constant `__DEV__` to `false`, error messages will be stripped from the bundle to save space. Only the error code will appear when an error is encountered. Follow the instructions in the error message to convert the error code back to the human-readable error message.
|
|
31
|
+
|
|
32
|
+
For instance, to recover the error text for the error with code `123`:
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
npx @solana/errors decode 123
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Adding a new error
|
|
39
|
+
|
|
40
|
+
1. Add a new exported error code constant to `src/codes.ts`.
|
|
41
|
+
2. Add that new constant to the `SolanaErrorCode` union in `src/codes.ts`.
|
|
42
|
+
3. If you would like the new error to encapsulate context about the error itself (eg. the public keys for which a transaction is missing signatures) define the shape of that context in `src/details.ts`.
|
|
43
|
+
4. Add the error's message to `src/messages.ts`. Any context values that you defined above will be interpolated into the message wherever you write `$key`, where `key` is the index of a value in the context (eg. ``'Missing a signature for account `$address`'``).
|
|
44
|
+
5. Publish a new version of `@solana/errors`.
|
|
45
|
+
6. Bump the version of `@solana/errors` in the package from which the error is thrown.
|
|
46
|
+
|
|
47
|
+
## Removing an error message
|
|
48
|
+
|
|
49
|
+
- Don't remove errors.
|
|
50
|
+
- Don't change the meaning of an error message.
|
|
51
|
+
- Don't change or reorder error codes.
|
|
52
|
+
- Don't change or remove members of an error's context.
|
|
53
|
+
|
|
54
|
+
When an older client throws an error, we want to make sure that they can always decode the error. If you make any of the changes above, old clients will, by definition, not have received your changes. This could make the errors that they throw impossible to decode going forward.
|
|
55
|
+
|
|
56
|
+
## Catching errors
|
|
57
|
+
|
|
58
|
+
When you catch a `SolanaError` and assert its error code using `isSolanaError()`, TypeScript will refine the error's context to the type associated with that error code. You can use that context to render useful error messages, or to make context-aware decisions that help your application to recover from the error.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import {
|
|
62
|
+
SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURE,
|
|
63
|
+
SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE,
|
|
64
|
+
isSolanaError,
|
|
65
|
+
} from '@solana/errors';
|
|
66
|
+
import { assertTransactionIsFullySigned, getSignatureFromTransaction } from '@solana/transactions';
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const transactionSignature = getSignatureFromTransaction(tx);
|
|
70
|
+
assertTransactionIsFullySigned(tx);
|
|
71
|
+
/* ... */
|
|
72
|
+
} catch (e) {
|
|
73
|
+
if (isSolanaError(e, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES)) {
|
|
74
|
+
displayError(
|
|
75
|
+
"We can't send this transaction without signatures for these addresses:\n- %s",
|
|
76
|
+
// The type of the `context` object is now refined to contain `addresses`.
|
|
77
|
+
e.context.addresses.join('\n- '),
|
|
78
|
+
);
|
|
79
|
+
return;
|
|
80
|
+
} else if (isSolanaError(e, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE)) {
|
|
81
|
+
if (!tx.feePayer) {
|
|
82
|
+
displayError('Choose a fee payer for this transaction before sending it');
|
|
83
|
+
} else {
|
|
84
|
+
displayError('The fee payer still needs to sign for this transaction');
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
```
|
package/bin/cli.js
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
12
|
+
var SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4;
|
|
13
|
+
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5;
|
|
14
|
+
var SOLANA_ERROR__NONCE_INVALID = 6;
|
|
15
|
+
var SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7;
|
|
16
|
+
|
|
17
|
+
// src/messages.ts
|
|
18
|
+
var SolanaErrorMessages = {
|
|
19
|
+
[SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]: "The network has progressed past the last block for which this transaction could have been committed.",
|
|
20
|
+
[SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: "Key pair bytes must be of length 64, got $byteLength.",
|
|
21
|
+
[SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: "No nonce account could be found at address `$nonceAccountAddress`",
|
|
22
|
+
[SOLANA_ERROR__NONCE_INVALID]: "The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`",
|
|
23
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: "The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was `$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds `Number.MAX_SAFE_INTEGER`.",
|
|
24
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses.",
|
|
25
|
+
[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."
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/message-formatter.ts
|
|
29
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
30
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
31
|
+
const message = messageFormatString.replace(
|
|
32
|
+
/(?<!\\)\$(\w+)/g,
|
|
33
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
34
|
+
);
|
|
35
|
+
return message;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/cli.ts
|
|
39
|
+
var program = new Command();
|
|
40
|
+
program.name("@solana/errors").description("Decode Solana JavaScript errors thrown in production").version(version);
|
|
41
|
+
program.command("decode").description("Decode a `SolanaErrorCode` to a human-readable message").argument("<code>", "numeric error code to decode", (rawCode) => {
|
|
42
|
+
const code = parseInt(rawCode, 10);
|
|
43
|
+
if (isNaN(code) || `${code}` !== rawCode) {
|
|
44
|
+
throw new InvalidArgumentError("It must be an integer");
|
|
45
|
+
}
|
|
46
|
+
if (!(code in SolanaErrorMessages)) {
|
|
47
|
+
throw new InvalidArgumentError("There exists no error with that code");
|
|
48
|
+
}
|
|
49
|
+
return code;
|
|
50
|
+
}).argument(
|
|
51
|
+
"[encodedContext]",
|
|
52
|
+
"encoded context to interpolate into the error message",
|
|
53
|
+
(encodedContext) => Object.fromEntries(new URLSearchParams(encodedContext).entries())
|
|
54
|
+
).action((code, context) => {
|
|
55
|
+
const message = getHumanReadableErrorMessage(code, context);
|
|
56
|
+
console.log(`
|
|
57
|
+
${chalk.bold(
|
|
58
|
+
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)("]")
|
|
59
|
+
) + chalk.rgb(19, 241, 149)(" Solana error code #" + code)}
|
|
60
|
+
- ${message}`);
|
|
61
|
+
if (context) {
|
|
62
|
+
console.log(`
|
|
63
|
+
${chalk.yellowBright(chalk.bold("[Context]"))}
|
|
64
|
+
${JSON.stringify(context, null, 4).split("\n").join("\n ")}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
function run(argv) {
|
|
68
|
+
program.parse(argv);
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
run
|
|
72
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ../build-scripts/env-shim.ts
|
|
4
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
5
|
+
|
|
6
|
+
// src/codes.ts
|
|
7
|
+
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
8
|
+
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
9
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
10
|
+
var SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4;
|
|
11
|
+
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5;
|
|
12
|
+
var SOLANA_ERROR__NONCE_INVALID = 6;
|
|
13
|
+
var SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7;
|
|
14
|
+
|
|
15
|
+
// src/messages.ts
|
|
16
|
+
var SolanaErrorMessages = {
|
|
17
|
+
[SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]: "The network has progressed past the last block for which this transaction could have been committed.",
|
|
18
|
+
[SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: "Key pair bytes must be of length 64, got $byteLength.",
|
|
19
|
+
[SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: "No nonce account could be found at address `$nonceAccountAddress`",
|
|
20
|
+
[SOLANA_ERROR__NONCE_INVALID]: "The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`",
|
|
21
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: "The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was `$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds `Number.MAX_SAFE_INTEGER`.",
|
|
22
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses.",
|
|
23
|
+
[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."
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/message-formatter.ts
|
|
27
|
+
function encodeValue(value) {
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
return (
|
|
30
|
+
/* "[" */
|
|
31
|
+
"%5B" + value.map(
|
|
32
|
+
(element) => typeof element === "string" ? encodeURIComponent(`"${element.replace(/"/g, '\\"')}"`) : encodeValue(element)
|
|
33
|
+
).join(
|
|
34
|
+
/* ", " */
|
|
35
|
+
"%2C%20"
|
|
36
|
+
) + /* "]" */
|
|
37
|
+
"%5D"
|
|
38
|
+
);
|
|
39
|
+
} else if (typeof value === "bigint") {
|
|
40
|
+
return `${value}n`;
|
|
41
|
+
} else {
|
|
42
|
+
return encodeURIComponent(
|
|
43
|
+
String(
|
|
44
|
+
Object.getPrototypeOf(value) === null ? (
|
|
45
|
+
// Plain objects with no protoype don't have a `toString` method.
|
|
46
|
+
// Convert them before stringifying them.
|
|
47
|
+
{ ...value }
|
|
48
|
+
) : value
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function encodeObjectContextEntry([key, value]) {
|
|
54
|
+
return `${key}=${encodeValue(value)}`;
|
|
55
|
+
}
|
|
56
|
+
function encodeContextObject(context) {
|
|
57
|
+
return Object.entries(context).map(encodeObjectContextEntry).join("&");
|
|
58
|
+
}
|
|
59
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
60
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
61
|
+
const message = messageFormatString.replace(
|
|
62
|
+
/(?<!\\)\$(\w+)/g,
|
|
63
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
64
|
+
);
|
|
65
|
+
return message;
|
|
66
|
+
}
|
|
67
|
+
function getErrorMessage(code, context = {}) {
|
|
68
|
+
if (__DEV__) {
|
|
69
|
+
return getHumanReadableErrorMessage(code, context);
|
|
70
|
+
} else {
|
|
71
|
+
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode ${code}`;
|
|
72
|
+
if (Object.keys(context).length) {
|
|
73
|
+
decodingAdviceMessage += ` $"${encodeContextObject(context)}"`;
|
|
74
|
+
}
|
|
75
|
+
return `${decodingAdviceMessage}\``;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/error.ts
|
|
80
|
+
function isSolanaError(e, code) {
|
|
81
|
+
const isSolanaError2 = e instanceof Error && e.name === "SolanaError";
|
|
82
|
+
if (isSolanaError2) {
|
|
83
|
+
if (code !== void 0) {
|
|
84
|
+
return e.context.__code === code;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
var SolanaError = class extends Error {
|
|
91
|
+
context;
|
|
92
|
+
constructor(...[code, context]) {
|
|
93
|
+
const message = getErrorMessage(code, context);
|
|
94
|
+
super(message);
|
|
95
|
+
this.context = {
|
|
96
|
+
__code: code,
|
|
97
|
+
...context
|
|
98
|
+
};
|
|
99
|
+
this.name = "SolanaError";
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED;
|
|
104
|
+
exports.SOLANA_ERROR__INVALID_KEYPAIR_BYTES = SOLANA_ERROR__INVALID_KEYPAIR_BYTES;
|
|
105
|
+
exports.SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;
|
|
106
|
+
exports.SOLANA_ERROR__NONCE_INVALID = SOLANA_ERROR__NONCE_INVALID;
|
|
107
|
+
exports.SOLANA_ERROR__RPC_INTEGER_OVERFLOW = SOLANA_ERROR__RPC_INTEGER_OVERFLOW;
|
|
108
|
+
exports.SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES;
|
|
109
|
+
exports.SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE;
|
|
110
|
+
exports.SolanaError = SolanaError;
|
|
111
|
+
exports.isSolanaError = isSolanaError;
|
|
112
|
+
//# sourceMappingURL=out.js.map
|
|
113
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/codes.ts","../src/messages.ts","../src/message-formatter.ts","../src/error.ts"],"names":["isSolanaError"],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACOhG,IAAM,+CAA+C;AACrD,IAAM,qDAAqD;AAC3D,IAAM,qCAAqC;AAC3C,IAAM,sCAAsC;AAC5C,IAAM,sCAAsC;AAC5C,IAAM,8BAA8B;AACpC,IAAM,wCAAwC;;;ACI9C,IAAM,sBAIR;AAAA,EACD,CAAC,mCAAmC,GAChC;AAAA,EACJ,CAAC,mCAAmC,GAAG;AAAA,EACvC,CAAC,qCAAqC,GAAG;AAAA,EACzC,CAAC,2BAA2B,GACxB;AAAA,EACJ,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;AClCA,SAAS,YAAY,OAAwB;AACzC,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB;AAAA;AAAA,MACc,QACV,MACK;AAAA,QAAI,aACD,OAAO,YAAY,WACb,mBAAmB,IAAI,QAAQ,QAAQ,MAAM,KAAK,CAAC,GAAG,IACtD,YAAY,OAAO;AAAA,MAC7B,EACC;AAAA;AAAA,QAAgB;AAAA,MAAQ;AAAA,MACnB;AAAA;AAAA,EAElB,WAAW,OAAO,UAAU,UAAU;AAClC,WAAO,GAAG,KAAK;AAAA,EACnB,OAAO;AACH,WAAO;AAAA,MACH;AAAA,QACI,OAAO,eAAe,KAAK,MAAM;AAAA;AAAA;AAAA,UAG3B,EAAE,GAAI,MAAiB;AAAA,YACvB;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,SAAS,yBAAyB,CAAC,KAAK,KAAK,GAAiD;AAC1F,SAAO,GAAG,GAAG,IAAI,YAAY,KAAK,CAAC;AACvC;AAEA,SAAS,oBAAoB,SAAiB;AAC1C,SAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,wBAAwB,EAAE,KAAK,GAAG;AACzE;AAEO,SAAS,6BACZ,MACA,UAAkB,CAAC,GACb;AACN,QAAM,sBAAsB,oBAAoB,IAAI;AACpD,QAAM,UAAU,oBAAoB;AAAA,IAAQ;AAAA,IAAmB,CAAC,WAAW,iBACvE,gBAAgB,UAAU,GAAG,QAAQ,YAAoC,CAAC,KAAK;AAAA,EACnF;AACA,SAAO;AACX;AAEO,SAAS,gBAAoD,MAAkB,UAAkB,CAAC,GAAW;AAChH,MAAI,SAAS;AACT,WAAO,6BAA6B,MAAM,OAAO;AAAA,EACrD,OAAO;AACH,QAAI,wBAAwB,iBAAiB,IAAI,8DAA8D,IAAI;AACnH,QAAI,OAAO,KAAK,OAAO,EAAE,QAAQ;AAM7B,+BAAyB,MAAM,oBAAoB,OAAO,CAAC;AAAA,IAC/D;AACA,WAAO,GAAG,qBAAqB;AAAA,EACnC;AACJ;;;AC7DO,SAAS,cACZ,GACA,MAC4B;AAC5B,QAAMA,iBAAgB,aAAa,SAAS,EAAE,SAAS;AACvD,MAAIA,gBAAe;AACf,QAAI,SAAS,QAAW;AACpB,aAAQ,EAA8B,QAAQ,WAAW;AAAA,IAC7D;AACA,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAQO,IAAM,cAAN,cAAgF,MAAM;AAAA,EAChF;AAAA,EACT,eACO,CAAC,MAAM,OAAO,GAGnB;AACE,UAAM,UAAU,gBAAgB,MAAM,OAAO;AAC7C,UAAM,OAAO;AACb,SAAK,UAAU;AAAA,MACX,QAAQ;AAAA,MACR,GAAG;AAAA,IACP;AAGA,SAAK,OAAO;AAAA,EAChB;AACJ","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't remove error codes\n * - Don't change or reorder error codes.\n */\nexport const SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1 as const;\nexport const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2 as const;\nexport const SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3 as const;\nexport const SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4 as const;\nexport const SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5 as const;\nexport const SOLANA_ERROR__NONCE_INVALID = 6 as const;\nexport const SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7 as const;\n\n/**\n * A union of every Solana error code\n *\n * You might be wondering why this is not a TypeScript enum or const enum.\n *\n * One of the goals of this library is to enable people to use some or none of it without having to\n * bundle all of it.\n *\n * If we made the set of error codes an enum then anyone who imported it (even if to only use a\n * single error code) would be forced to bundle every code and its label.\n *\n * Const enums appear to solve this problem by letting the compiler inline only the codes that are\n * actually used. Unfortunately exporting ambient (const) enums from a library like `@solana/errors`\n * is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850\n */\nexport type SolanaErrorCode =\n | typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES\n | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE\n | typeof SOLANA_ERROR__RPC_INTEGER_OVERFLOW\n | typeof SOLANA_ERROR__INVALID_KEYPAIR_BYTES\n | typeof SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED\n | typeof SOLANA_ERROR__NONCE_INVALID\n | typeof SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;\n","import {\n SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED,\n SOLANA_ERROR__INVALID_KEYPAIR_BYTES,\n SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,\n SOLANA_ERROR__NONCE_INVALID,\n SOLANA_ERROR__RPC_INTEGER_OVERFLOW,\n SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES,\n SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE,\n SolanaErrorCode,\n} from './codes';\n\n/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't change the meaning of an error message.\n */\nexport const SolanaErrorMessages: Readonly<{\n // This type makes this data structure exhaustive with respect to `SolanaErrorCode`.\n // TypeScript will fail to build this project if add an error code without a message.\n [P in SolanaErrorCode]: string;\n}> = {\n [SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]:\n 'The network has progressed past the last block for which this transaction could have been committed.',\n [SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: 'Key pair bytes must be of length 64, got $byteLength.',\n [SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: 'No nonce account could be found at address `$nonceAccountAddress`',\n [SOLANA_ERROR__NONCE_INVALID]:\n 'The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`',\n [SOLANA_ERROR__RPC_INTEGER_OVERFLOW]:\n 'The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was ' +\n '`$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds ' +\n '`Number.MAX_SAFE_INTEGER`.',\n [SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: 'Transaction is missing signatures for addresses: $addresses.',\n [SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]:\n \"Could not determine this transaction's signature. Make sure that the transaction has \" +\n 'been signed by its fee payer.',\n};\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorMessages } from './messages';\n\nfunction encodeValue(value: unknown): string {\n if (Array.isArray(value)) {\n return (\n /* \"[\" */ '%5B' +\n value\n .map(element =>\n typeof element === 'string'\n ? encodeURIComponent(`\"${element.replace(/\"/g, '\\\\\"')}\"`)\n : encodeValue(element),\n )\n .join(/* \", \" */ '%2C%20') +\n /* \"]\" */ '%5D'\n );\n } else if (typeof value === 'bigint') {\n return `${value}n`;\n } else {\n return encodeURIComponent(\n String(\n Object.getPrototypeOf(value) === null\n ? // Plain objects with no protoype don't have a `toString` method.\n // Convert them before stringifying them.\n { ...(value as object) }\n : value,\n ),\n );\n }\n}\n\nfunction encodeObjectContextEntry([key, value]: [string, unknown]): `${typeof key}=${string}` {\n return `${key}=${encodeValue(value)}`;\n}\n\nfunction encodeContextObject(context: object) {\n return Object.entries(context).map(encodeObjectContextEntry).join('&');\n}\n\nexport function getHumanReadableErrorMessage<TErrorCode extends SolanaErrorCode>(\n code: TErrorCode,\n context: object = {},\n): string {\n const messageFormatString = SolanaErrorMessages[code];\n const message = messageFormatString.replace(/(?<!\\\\)\\$(\\w+)/g, (substring, variableName) =>\n variableName in context ? `${context[variableName as keyof typeof context]}` : substring,\n );\n return message;\n}\n\nexport function getErrorMessage<TErrorCode extends SolanaErrorCode>(code: TErrorCode, context: object = {}): string {\n if (__DEV__) {\n return getHumanReadableErrorMessage(code, context);\n } else {\n let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \\`npx @solana/errors decode ${code}`;\n if (Object.keys(context).length) {\n /**\n * DANGER: Be sure that the shell command is escaped in such a way that makes it\n * impossible for someone to craft malicious context values that would result in\n * an exploit against anyone who bindly copy/pastes it into their terminal.\n */\n decodingAdviceMessage += ` $\"${encodeContextObject(context)}\"`;\n }\n return `${decodingAdviceMessage}\\``;\n }\n}\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorContext } from './context';\nimport { getErrorMessage } from './message-formatter';\n\nexport function isSolanaError<TErrorCode extends SolanaErrorCode>(\n e: unknown,\n code?: TErrorCode,\n): e is SolanaError<TErrorCode> {\n const isSolanaError = e instanceof Error && e.name === 'SolanaError';\n if (isSolanaError) {\n if (code !== undefined) {\n return (e as SolanaError<TErrorCode>).context.__code === code;\n }\n return true;\n }\n return false;\n}\n\ntype SolanaErrorCodedContext = Readonly<{\n [P in SolanaErrorCode]: (SolanaErrorContext[P] extends undefined ? object : SolanaErrorContext[P]) & {\n __code: P;\n };\n}>;\n\nexport class SolanaError<TErrorCode extends SolanaErrorCode = SolanaErrorCode> extends Error {\n readonly context: SolanaErrorCodedContext[TErrorCode];\n constructor(\n ...[code, context]: SolanaErrorContext[TErrorCode] extends undefined\n ? [code: TErrorCode]\n : [code: TErrorCode, context: SolanaErrorContext[TErrorCode]]\n ) {\n const message = getErrorMessage(code, context);\n super(message);\n this.context = {\n __code: code,\n ...context,\n } as SolanaErrorCodedContext[TErrorCode];\n // This is necessary so that `isSolanaError()` can identify a `SolanaError` without having\n // to import the class for use in an `instanceof` check.\n this.name = 'SolanaError';\n }\n}\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// ../build-scripts/env-shim.ts
|
|
2
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
3
|
+
|
|
4
|
+
// src/codes.ts
|
|
5
|
+
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
6
|
+
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
7
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
8
|
+
var SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4;
|
|
9
|
+
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5;
|
|
10
|
+
var SOLANA_ERROR__NONCE_INVALID = 6;
|
|
11
|
+
var SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7;
|
|
12
|
+
|
|
13
|
+
// src/messages.ts
|
|
14
|
+
var SolanaErrorMessages = {
|
|
15
|
+
[SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]: "The network has progressed past the last block for which this transaction could have been committed.",
|
|
16
|
+
[SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: "Key pair bytes must be of length 64, got $byteLength.",
|
|
17
|
+
[SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: "No nonce account could be found at address `$nonceAccountAddress`",
|
|
18
|
+
[SOLANA_ERROR__NONCE_INVALID]: "The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`",
|
|
19
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: "The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was `$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds `Number.MAX_SAFE_INTEGER`.",
|
|
20
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses.",
|
|
21
|
+
[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."
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/message-formatter.ts
|
|
25
|
+
function encodeValue(value) {
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return (
|
|
28
|
+
/* "[" */
|
|
29
|
+
"%5B" + value.map(
|
|
30
|
+
(element) => typeof element === "string" ? encodeURIComponent(`"${element.replace(/"/g, '\\"')}"`) : encodeValue(element)
|
|
31
|
+
).join(
|
|
32
|
+
/* ", " */
|
|
33
|
+
"%2C%20"
|
|
34
|
+
) + /* "]" */
|
|
35
|
+
"%5D"
|
|
36
|
+
);
|
|
37
|
+
} else if (typeof value === "bigint") {
|
|
38
|
+
return `${value}n`;
|
|
39
|
+
} else {
|
|
40
|
+
return encodeURIComponent(
|
|
41
|
+
String(
|
|
42
|
+
Object.getPrototypeOf(value) === null ? (
|
|
43
|
+
// Plain objects with no protoype don't have a `toString` method.
|
|
44
|
+
// Convert them before stringifying them.
|
|
45
|
+
{ ...value }
|
|
46
|
+
) : value
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function encodeObjectContextEntry([key, value]) {
|
|
52
|
+
return `${key}=${encodeValue(value)}`;
|
|
53
|
+
}
|
|
54
|
+
function encodeContextObject(context) {
|
|
55
|
+
return Object.entries(context).map(encodeObjectContextEntry).join("&");
|
|
56
|
+
}
|
|
57
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
58
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
59
|
+
const message = messageFormatString.replace(
|
|
60
|
+
/(?<!\\)\$(\w+)/g,
|
|
61
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
62
|
+
);
|
|
63
|
+
return message;
|
|
64
|
+
}
|
|
65
|
+
function getErrorMessage(code, context = {}) {
|
|
66
|
+
if (__DEV__) {
|
|
67
|
+
return getHumanReadableErrorMessage(code, context);
|
|
68
|
+
} else {
|
|
69
|
+
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode ${code}`;
|
|
70
|
+
if (Object.keys(context).length) {
|
|
71
|
+
decodingAdviceMessage += ` $"${encodeContextObject(context)}"`;
|
|
72
|
+
}
|
|
73
|
+
return `${decodingAdviceMessage}\``;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/error.ts
|
|
78
|
+
function isSolanaError(e, code) {
|
|
79
|
+
const isSolanaError2 = e instanceof Error && e.name === "SolanaError";
|
|
80
|
+
if (isSolanaError2) {
|
|
81
|
+
if (code !== void 0) {
|
|
82
|
+
return e.context.__code === code;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
var SolanaError = class extends Error {
|
|
89
|
+
context;
|
|
90
|
+
constructor(...[code, context]) {
|
|
91
|
+
const message = getErrorMessage(code, context);
|
|
92
|
+
super(message);
|
|
93
|
+
this.context = {
|
|
94
|
+
__code: code,
|
|
95
|
+
...context
|
|
96
|
+
};
|
|
97
|
+
this.name = "SolanaError";
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED, SOLANA_ERROR__INVALID_KEYPAIR_BYTES, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND, SOLANA_ERROR__NONCE_INVALID, SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
102
|
+
//# sourceMappingURL=out.js.map
|
|
103
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/codes.ts","../src/messages.ts","../src/message-formatter.ts","../src/error.ts"],"names":["isSolanaError"],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACOhG,IAAM,+CAA+C;AACrD,IAAM,qDAAqD;AAC3D,IAAM,qCAAqC;AAC3C,IAAM,sCAAsC;AAC5C,IAAM,sCAAsC;AAC5C,IAAM,8BAA8B;AACpC,IAAM,wCAAwC;;;ACI9C,IAAM,sBAIR;AAAA,EACD,CAAC,mCAAmC,GAChC;AAAA,EACJ,CAAC,mCAAmC,GAAG;AAAA,EACvC,CAAC,qCAAqC,GAAG;AAAA,EACzC,CAAC,2BAA2B,GACxB;AAAA,EACJ,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;AClCA,SAAS,YAAY,OAAwB;AACzC,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB;AAAA;AAAA,MACc,QACV,MACK;AAAA,QAAI,aACD,OAAO,YAAY,WACb,mBAAmB,IAAI,QAAQ,QAAQ,MAAM,KAAK,CAAC,GAAG,IACtD,YAAY,OAAO;AAAA,MAC7B,EACC;AAAA;AAAA,QAAgB;AAAA,MAAQ;AAAA,MACnB;AAAA;AAAA,EAElB,WAAW,OAAO,UAAU,UAAU;AAClC,WAAO,GAAG,KAAK;AAAA,EACnB,OAAO;AACH,WAAO;AAAA,MACH;AAAA,QACI,OAAO,eAAe,KAAK,MAAM;AAAA;AAAA;AAAA,UAG3B,EAAE,GAAI,MAAiB;AAAA,YACvB;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,SAAS,yBAAyB,CAAC,KAAK,KAAK,GAAiD;AAC1F,SAAO,GAAG,GAAG,IAAI,YAAY,KAAK,CAAC;AACvC;AAEA,SAAS,oBAAoB,SAAiB;AAC1C,SAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,wBAAwB,EAAE,KAAK,GAAG;AACzE;AAEO,SAAS,6BACZ,MACA,UAAkB,CAAC,GACb;AACN,QAAM,sBAAsB,oBAAoB,IAAI;AACpD,QAAM,UAAU,oBAAoB;AAAA,IAAQ;AAAA,IAAmB,CAAC,WAAW,iBACvE,gBAAgB,UAAU,GAAG,QAAQ,YAAoC,CAAC,KAAK;AAAA,EACnF;AACA,SAAO;AACX;AAEO,SAAS,gBAAoD,MAAkB,UAAkB,CAAC,GAAW;AAChH,MAAI,SAAS;AACT,WAAO,6BAA6B,MAAM,OAAO;AAAA,EACrD,OAAO;AACH,QAAI,wBAAwB,iBAAiB,IAAI,8DAA8D,IAAI;AACnH,QAAI,OAAO,KAAK,OAAO,EAAE,QAAQ;AAM7B,+BAAyB,MAAM,oBAAoB,OAAO,CAAC;AAAA,IAC/D;AACA,WAAO,GAAG,qBAAqB;AAAA,EACnC;AACJ;;;AC7DO,SAAS,cACZ,GACA,MAC4B;AAC5B,QAAMA,iBAAgB,aAAa,SAAS,EAAE,SAAS;AACvD,MAAIA,gBAAe;AACf,QAAI,SAAS,QAAW;AACpB,aAAQ,EAA8B,QAAQ,WAAW;AAAA,IAC7D;AACA,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAQO,IAAM,cAAN,cAAgF,MAAM;AAAA,EAChF;AAAA,EACT,eACO,CAAC,MAAM,OAAO,GAGnB;AACE,UAAM,UAAU,gBAAgB,MAAM,OAAO;AAC7C,UAAM,OAAO;AACb,SAAK,UAAU;AAAA,MACX,QAAQ;AAAA,MACR,GAAG;AAAA,IACP;AAGA,SAAK,OAAO;AAAA,EAChB;AACJ","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't remove error codes\n * - Don't change or reorder error codes.\n */\nexport const SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1 as const;\nexport const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2 as const;\nexport const SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3 as const;\nexport const SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4 as const;\nexport const SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5 as const;\nexport const SOLANA_ERROR__NONCE_INVALID = 6 as const;\nexport const SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7 as const;\n\n/**\n * A union of every Solana error code\n *\n * You might be wondering why this is not a TypeScript enum or const enum.\n *\n * One of the goals of this library is to enable people to use some or none of it without having to\n * bundle all of it.\n *\n * If we made the set of error codes an enum then anyone who imported it (even if to only use a\n * single error code) would be forced to bundle every code and its label.\n *\n * Const enums appear to solve this problem by letting the compiler inline only the codes that are\n * actually used. Unfortunately exporting ambient (const) enums from a library like `@solana/errors`\n * is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850\n */\nexport type SolanaErrorCode =\n | typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES\n | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE\n | typeof SOLANA_ERROR__RPC_INTEGER_OVERFLOW\n | typeof SOLANA_ERROR__INVALID_KEYPAIR_BYTES\n | typeof SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED\n | typeof SOLANA_ERROR__NONCE_INVALID\n | typeof SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;\n","import {\n SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED,\n SOLANA_ERROR__INVALID_KEYPAIR_BYTES,\n SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,\n SOLANA_ERROR__NONCE_INVALID,\n SOLANA_ERROR__RPC_INTEGER_OVERFLOW,\n SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES,\n SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE,\n SolanaErrorCode,\n} from './codes';\n\n/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't change the meaning of an error message.\n */\nexport const SolanaErrorMessages: Readonly<{\n // This type makes this data structure exhaustive with respect to `SolanaErrorCode`.\n // TypeScript will fail to build this project if add an error code without a message.\n [P in SolanaErrorCode]: string;\n}> = {\n [SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]:\n 'The network has progressed past the last block for which this transaction could have been committed.',\n [SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: 'Key pair bytes must be of length 64, got $byteLength.',\n [SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: 'No nonce account could be found at address `$nonceAccountAddress`',\n [SOLANA_ERROR__NONCE_INVALID]:\n 'The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`',\n [SOLANA_ERROR__RPC_INTEGER_OVERFLOW]:\n 'The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was ' +\n '`$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds ' +\n '`Number.MAX_SAFE_INTEGER`.',\n [SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: 'Transaction is missing signatures for addresses: $addresses.',\n [SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]:\n \"Could not determine this transaction's signature. Make sure that the transaction has \" +\n 'been signed by its fee payer.',\n};\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorMessages } from './messages';\n\nfunction encodeValue(value: unknown): string {\n if (Array.isArray(value)) {\n return (\n /* \"[\" */ '%5B' +\n value\n .map(element =>\n typeof element === 'string'\n ? encodeURIComponent(`\"${element.replace(/\"/g, '\\\\\"')}\"`)\n : encodeValue(element),\n )\n .join(/* \", \" */ '%2C%20') +\n /* \"]\" */ '%5D'\n );\n } else if (typeof value === 'bigint') {\n return `${value}n`;\n } else {\n return encodeURIComponent(\n String(\n Object.getPrototypeOf(value) === null\n ? // Plain objects with no protoype don't have a `toString` method.\n // Convert them before stringifying them.\n { ...(value as object) }\n : value,\n ),\n );\n }\n}\n\nfunction encodeObjectContextEntry([key, value]: [string, unknown]): `${typeof key}=${string}` {\n return `${key}=${encodeValue(value)}`;\n}\n\nfunction encodeContextObject(context: object) {\n return Object.entries(context).map(encodeObjectContextEntry).join('&');\n}\n\nexport function getHumanReadableErrorMessage<TErrorCode extends SolanaErrorCode>(\n code: TErrorCode,\n context: object = {},\n): string {\n const messageFormatString = SolanaErrorMessages[code];\n const message = messageFormatString.replace(/(?<!\\\\)\\$(\\w+)/g, (substring, variableName) =>\n variableName in context ? `${context[variableName as keyof typeof context]}` : substring,\n );\n return message;\n}\n\nexport function getErrorMessage<TErrorCode extends SolanaErrorCode>(code: TErrorCode, context: object = {}): string {\n if (__DEV__) {\n return getHumanReadableErrorMessage(code, context);\n } else {\n let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \\`npx @solana/errors decode ${code}`;\n if (Object.keys(context).length) {\n /**\n * DANGER: Be sure that the shell command is escaped in such a way that makes it\n * impossible for someone to craft malicious context values that would result in\n * an exploit against anyone who bindly copy/pastes it into their terminal.\n */\n decodingAdviceMessage += ` $\"${encodeContextObject(context)}\"`;\n }\n return `${decodingAdviceMessage}\\``;\n }\n}\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorContext } from './context';\nimport { getErrorMessage } from './message-formatter';\n\nexport function isSolanaError<TErrorCode extends SolanaErrorCode>(\n e: unknown,\n code?: TErrorCode,\n): e is SolanaError<TErrorCode> {\n const isSolanaError = e instanceof Error && e.name === 'SolanaError';\n if (isSolanaError) {\n if (code !== undefined) {\n return (e as SolanaError<TErrorCode>).context.__code === code;\n }\n return true;\n }\n return false;\n}\n\ntype SolanaErrorCodedContext = Readonly<{\n [P in SolanaErrorCode]: (SolanaErrorContext[P] extends undefined ? object : SolanaErrorContext[P]) & {\n __code: P;\n };\n}>;\n\nexport class SolanaError<TErrorCode extends SolanaErrorCode = SolanaErrorCode> extends Error {\n readonly context: SolanaErrorCodedContext[TErrorCode];\n constructor(\n ...[code, context]: SolanaErrorContext[TErrorCode] extends undefined\n ? [code: TErrorCode]\n : [code: TErrorCode, context: SolanaErrorContext[TErrorCode]]\n ) {\n const message = getErrorMessage(code, context);\n super(message);\n this.context = {\n __code: code,\n ...context,\n } as SolanaErrorCodedContext[TErrorCode];\n // This is necessary so that `isSolanaError()` can identify a `SolanaError` without having\n // to import the class for use in an `instanceof` check.\n this.name = 'SolanaError';\n }\n}\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// ../build-scripts/env-shim.ts
|
|
2
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
3
|
+
|
|
4
|
+
// src/codes.ts
|
|
5
|
+
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
6
|
+
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
7
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
8
|
+
var SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4;
|
|
9
|
+
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5;
|
|
10
|
+
var SOLANA_ERROR__NONCE_INVALID = 6;
|
|
11
|
+
var SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7;
|
|
12
|
+
|
|
13
|
+
// src/messages.ts
|
|
14
|
+
var SolanaErrorMessages = {
|
|
15
|
+
[SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]: "The network has progressed past the last block for which this transaction could have been committed.",
|
|
16
|
+
[SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: "Key pair bytes must be of length 64, got $byteLength.",
|
|
17
|
+
[SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: "No nonce account could be found at address `$nonceAccountAddress`",
|
|
18
|
+
[SOLANA_ERROR__NONCE_INVALID]: "The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`",
|
|
19
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: "The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was `$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds `Number.MAX_SAFE_INTEGER`.",
|
|
20
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses.",
|
|
21
|
+
[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."
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/message-formatter.ts
|
|
25
|
+
function encodeValue(value) {
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return (
|
|
28
|
+
/* "[" */
|
|
29
|
+
"%5B" + value.map(
|
|
30
|
+
(element) => typeof element === "string" ? encodeURIComponent(`"${element.replace(/"/g, '\\"')}"`) : encodeValue(element)
|
|
31
|
+
).join(
|
|
32
|
+
/* ", " */
|
|
33
|
+
"%2C%20"
|
|
34
|
+
) + /* "]" */
|
|
35
|
+
"%5D"
|
|
36
|
+
);
|
|
37
|
+
} else if (typeof value === "bigint") {
|
|
38
|
+
return `${value}n`;
|
|
39
|
+
} else {
|
|
40
|
+
return encodeURIComponent(
|
|
41
|
+
String(
|
|
42
|
+
Object.getPrototypeOf(value) === null ? (
|
|
43
|
+
// Plain objects with no protoype don't have a `toString` method.
|
|
44
|
+
// Convert them before stringifying them.
|
|
45
|
+
{ ...value }
|
|
46
|
+
) : value
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function encodeObjectContextEntry([key, value]) {
|
|
52
|
+
return `${key}=${encodeValue(value)}`;
|
|
53
|
+
}
|
|
54
|
+
function encodeContextObject(context) {
|
|
55
|
+
return Object.entries(context).map(encodeObjectContextEntry).join("&");
|
|
56
|
+
}
|
|
57
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
58
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
59
|
+
const message = messageFormatString.replace(
|
|
60
|
+
/(?<!\\)\$(\w+)/g,
|
|
61
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
62
|
+
);
|
|
63
|
+
return message;
|
|
64
|
+
}
|
|
65
|
+
function getErrorMessage(code, context = {}) {
|
|
66
|
+
if (__DEV__) {
|
|
67
|
+
return getHumanReadableErrorMessage(code, context);
|
|
68
|
+
} else {
|
|
69
|
+
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode ${code}`;
|
|
70
|
+
if (Object.keys(context).length) {
|
|
71
|
+
decodingAdviceMessage += ` $"${encodeContextObject(context)}"`;
|
|
72
|
+
}
|
|
73
|
+
return `${decodingAdviceMessage}\``;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/error.ts
|
|
78
|
+
function isSolanaError(e, code) {
|
|
79
|
+
const isSolanaError2 = e instanceof Error && e.name === "SolanaError";
|
|
80
|
+
if (isSolanaError2) {
|
|
81
|
+
if (code !== void 0) {
|
|
82
|
+
return e.context.__code === code;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
var SolanaError = class extends Error {
|
|
89
|
+
context;
|
|
90
|
+
constructor(...[code, context]) {
|
|
91
|
+
const message = getErrorMessage(code, context);
|
|
92
|
+
super(message);
|
|
93
|
+
this.context = {
|
|
94
|
+
__code: code,
|
|
95
|
+
...context
|
|
96
|
+
};
|
|
97
|
+
this.name = "SolanaError";
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED, SOLANA_ERROR__INVALID_KEYPAIR_BYTES, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND, SOLANA_ERROR__NONCE_INVALID, SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
102
|
+
//# sourceMappingURL=out.js.map
|
|
103
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/codes.ts","../src/messages.ts","../src/message-formatter.ts","../src/error.ts"],"names":["isSolanaError"],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACOhG,IAAM,+CAA+C;AACrD,IAAM,qDAAqD;AAC3D,IAAM,qCAAqC;AAC3C,IAAM,sCAAsC;AAC5C,IAAM,sCAAsC;AAC5C,IAAM,8BAA8B;AACpC,IAAM,wCAAwC;;;ACI9C,IAAM,sBAIR;AAAA,EACD,CAAC,mCAAmC,GAChC;AAAA,EACJ,CAAC,mCAAmC,GAAG;AAAA,EACvC,CAAC,qCAAqC,GAAG;AAAA,EACzC,CAAC,2BAA2B,GACxB;AAAA,EACJ,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;AClCA,SAAS,YAAY,OAAwB;AACzC,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB;AAAA;AAAA,MACc,QACV,MACK;AAAA,QAAI,aACD,OAAO,YAAY,WACb,mBAAmB,IAAI,QAAQ,QAAQ,MAAM,KAAK,CAAC,GAAG,IACtD,YAAY,OAAO;AAAA,MAC7B,EACC;AAAA;AAAA,QAAgB;AAAA,MAAQ;AAAA,MACnB;AAAA;AAAA,EAElB,WAAW,OAAO,UAAU,UAAU;AAClC,WAAO,GAAG,KAAK;AAAA,EACnB,OAAO;AACH,WAAO;AAAA,MACH;AAAA,QACI,OAAO,eAAe,KAAK,MAAM;AAAA;AAAA;AAAA,UAG3B,EAAE,GAAI,MAAiB;AAAA,YACvB;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,SAAS,yBAAyB,CAAC,KAAK,KAAK,GAAiD;AAC1F,SAAO,GAAG,GAAG,IAAI,YAAY,KAAK,CAAC;AACvC;AAEA,SAAS,oBAAoB,SAAiB;AAC1C,SAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,wBAAwB,EAAE,KAAK,GAAG;AACzE;AAEO,SAAS,6BACZ,MACA,UAAkB,CAAC,GACb;AACN,QAAM,sBAAsB,oBAAoB,IAAI;AACpD,QAAM,UAAU,oBAAoB;AAAA,IAAQ;AAAA,IAAmB,CAAC,WAAW,iBACvE,gBAAgB,UAAU,GAAG,QAAQ,YAAoC,CAAC,KAAK;AAAA,EACnF;AACA,SAAO;AACX;AAEO,SAAS,gBAAoD,MAAkB,UAAkB,CAAC,GAAW;AAChH,MAAI,SAAS;AACT,WAAO,6BAA6B,MAAM,OAAO;AAAA,EACrD,OAAO;AACH,QAAI,wBAAwB,iBAAiB,IAAI,8DAA8D,IAAI;AACnH,QAAI,OAAO,KAAK,OAAO,EAAE,QAAQ;AAM7B,+BAAyB,MAAM,oBAAoB,OAAO,CAAC;AAAA,IAC/D;AACA,WAAO,GAAG,qBAAqB;AAAA,EACnC;AACJ;;;AC7DO,SAAS,cACZ,GACA,MAC4B;AAC5B,QAAMA,iBAAgB,aAAa,SAAS,EAAE,SAAS;AACvD,MAAIA,gBAAe;AACf,QAAI,SAAS,QAAW;AACpB,aAAQ,EAA8B,QAAQ,WAAW;AAAA,IAC7D;AACA,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAQO,IAAM,cAAN,cAAgF,MAAM;AAAA,EAChF;AAAA,EACT,eACO,CAAC,MAAM,OAAO,GAGnB;AACE,UAAM,UAAU,gBAAgB,MAAM,OAAO;AAC7C,UAAM,OAAO;AACb,SAAK,UAAU;AAAA,MACX,QAAQ;AAAA,MACR,GAAG;AAAA,IACP;AAGA,SAAK,OAAO;AAAA,EAChB;AACJ","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't remove error codes\n * - Don't change or reorder error codes.\n */\nexport const SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1 as const;\nexport const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2 as const;\nexport const SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3 as const;\nexport const SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4 as const;\nexport const SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5 as const;\nexport const SOLANA_ERROR__NONCE_INVALID = 6 as const;\nexport const SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7 as const;\n\n/**\n * A union of every Solana error code\n *\n * You might be wondering why this is not a TypeScript enum or const enum.\n *\n * One of the goals of this library is to enable people to use some or none of it without having to\n * bundle all of it.\n *\n * If we made the set of error codes an enum then anyone who imported it (even if to only use a\n * single error code) would be forced to bundle every code and its label.\n *\n * Const enums appear to solve this problem by letting the compiler inline only the codes that are\n * actually used. Unfortunately exporting ambient (const) enums from a library like `@solana/errors`\n * is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850\n */\nexport type SolanaErrorCode =\n | typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES\n | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE\n | typeof SOLANA_ERROR__RPC_INTEGER_OVERFLOW\n | typeof SOLANA_ERROR__INVALID_KEYPAIR_BYTES\n | typeof SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED\n | typeof SOLANA_ERROR__NONCE_INVALID\n | typeof SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;\n","import {\n SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED,\n SOLANA_ERROR__INVALID_KEYPAIR_BYTES,\n SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,\n SOLANA_ERROR__NONCE_INVALID,\n SOLANA_ERROR__RPC_INTEGER_OVERFLOW,\n SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES,\n SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE,\n SolanaErrorCode,\n} from './codes';\n\n/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't change the meaning of an error message.\n */\nexport const SolanaErrorMessages: Readonly<{\n // This type makes this data structure exhaustive with respect to `SolanaErrorCode`.\n // TypeScript will fail to build this project if add an error code without a message.\n [P in SolanaErrorCode]: string;\n}> = {\n [SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]:\n 'The network has progressed past the last block for which this transaction could have been committed.',\n [SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: 'Key pair bytes must be of length 64, got $byteLength.',\n [SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: 'No nonce account could be found at address `$nonceAccountAddress`',\n [SOLANA_ERROR__NONCE_INVALID]:\n 'The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`',\n [SOLANA_ERROR__RPC_INTEGER_OVERFLOW]:\n 'The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was ' +\n '`$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds ' +\n '`Number.MAX_SAFE_INTEGER`.',\n [SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: 'Transaction is missing signatures for addresses: $addresses.',\n [SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]:\n \"Could not determine this transaction's signature. Make sure that the transaction has \" +\n 'been signed by its fee payer.',\n};\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorMessages } from './messages';\n\nfunction encodeValue(value: unknown): string {\n if (Array.isArray(value)) {\n return (\n /* \"[\" */ '%5B' +\n value\n .map(element =>\n typeof element === 'string'\n ? encodeURIComponent(`\"${element.replace(/\"/g, '\\\\\"')}\"`)\n : encodeValue(element),\n )\n .join(/* \", \" */ '%2C%20') +\n /* \"]\" */ '%5D'\n );\n } else if (typeof value === 'bigint') {\n return `${value}n`;\n } else {\n return encodeURIComponent(\n String(\n Object.getPrototypeOf(value) === null\n ? // Plain objects with no protoype don't have a `toString` method.\n // Convert them before stringifying them.\n { ...(value as object) }\n : value,\n ),\n );\n }\n}\n\nfunction encodeObjectContextEntry([key, value]: [string, unknown]): `${typeof key}=${string}` {\n return `${key}=${encodeValue(value)}`;\n}\n\nfunction encodeContextObject(context: object) {\n return Object.entries(context).map(encodeObjectContextEntry).join('&');\n}\n\nexport function getHumanReadableErrorMessage<TErrorCode extends SolanaErrorCode>(\n code: TErrorCode,\n context: object = {},\n): string {\n const messageFormatString = SolanaErrorMessages[code];\n const message = messageFormatString.replace(/(?<!\\\\)\\$(\\w+)/g, (substring, variableName) =>\n variableName in context ? `${context[variableName as keyof typeof context]}` : substring,\n );\n return message;\n}\n\nexport function getErrorMessage<TErrorCode extends SolanaErrorCode>(code: TErrorCode, context: object = {}): string {\n if (__DEV__) {\n return getHumanReadableErrorMessage(code, context);\n } else {\n let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \\`npx @solana/errors decode ${code}`;\n if (Object.keys(context).length) {\n /**\n * DANGER: Be sure that the shell command is escaped in such a way that makes it\n * impossible for someone to craft malicious context values that would result in\n * an exploit against anyone who bindly copy/pastes it into their terminal.\n */\n decodingAdviceMessage += ` $\"${encodeContextObject(context)}\"`;\n }\n return `${decodingAdviceMessage}\\``;\n }\n}\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorContext } from './context';\nimport { getErrorMessage } from './message-formatter';\n\nexport function isSolanaError<TErrorCode extends SolanaErrorCode>(\n e: unknown,\n code?: TErrorCode,\n): e is SolanaError<TErrorCode> {\n const isSolanaError = e instanceof Error && e.name === 'SolanaError';\n if (isSolanaError) {\n if (code !== undefined) {\n return (e as SolanaError<TErrorCode>).context.__code === code;\n }\n return true;\n }\n return false;\n}\n\ntype SolanaErrorCodedContext = Readonly<{\n [P in SolanaErrorCode]: (SolanaErrorContext[P] extends undefined ? object : SolanaErrorContext[P]) & {\n __code: P;\n };\n}>;\n\nexport class SolanaError<TErrorCode extends SolanaErrorCode = SolanaErrorCode> extends Error {\n readonly context: SolanaErrorCodedContext[TErrorCode];\n constructor(\n ...[code, context]: SolanaErrorContext[TErrorCode] extends undefined\n ? [code: TErrorCode]\n : [code: TErrorCode, context: SolanaErrorContext[TErrorCode]]\n ) {\n const message = getErrorMessage(code, context);\n super(message);\n this.context = {\n __code: code,\n ...context,\n } as SolanaErrorCodedContext[TErrorCode];\n // This is necessary so that `isSolanaError()` can identify a `SolanaError` without having\n // to import the class for use in an `instanceof` check.\n this.name = 'SolanaError';\n }\n}\n"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ../build-scripts/env-shim.ts
|
|
4
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
5
|
+
|
|
6
|
+
// src/codes.ts
|
|
7
|
+
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
8
|
+
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
9
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
10
|
+
var SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4;
|
|
11
|
+
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5;
|
|
12
|
+
var SOLANA_ERROR__NONCE_INVALID = 6;
|
|
13
|
+
var SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7;
|
|
14
|
+
|
|
15
|
+
// src/messages.ts
|
|
16
|
+
var SolanaErrorMessages = {
|
|
17
|
+
[SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]: "The network has progressed past the last block for which this transaction could have been committed.",
|
|
18
|
+
[SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: "Key pair bytes must be of length 64, got $byteLength.",
|
|
19
|
+
[SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: "No nonce account could be found at address `$nonceAccountAddress`",
|
|
20
|
+
[SOLANA_ERROR__NONCE_INVALID]: "The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`",
|
|
21
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: "The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was `$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds `Number.MAX_SAFE_INTEGER`.",
|
|
22
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses.",
|
|
23
|
+
[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."
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/message-formatter.ts
|
|
27
|
+
function encodeValue(value) {
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
return (
|
|
30
|
+
/* "[" */
|
|
31
|
+
"%5B" + value.map(
|
|
32
|
+
(element) => typeof element === "string" ? encodeURIComponent(`"${element.replace(/"/g, '\\"')}"`) : encodeValue(element)
|
|
33
|
+
).join(
|
|
34
|
+
/* ", " */
|
|
35
|
+
"%2C%20"
|
|
36
|
+
) + /* "]" */
|
|
37
|
+
"%5D"
|
|
38
|
+
);
|
|
39
|
+
} else if (typeof value === "bigint") {
|
|
40
|
+
return `${value}n`;
|
|
41
|
+
} else {
|
|
42
|
+
return encodeURIComponent(
|
|
43
|
+
String(
|
|
44
|
+
Object.getPrototypeOf(value) === null ? (
|
|
45
|
+
// Plain objects with no protoype don't have a `toString` method.
|
|
46
|
+
// Convert them before stringifying them.
|
|
47
|
+
{ ...value }
|
|
48
|
+
) : value
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function encodeObjectContextEntry([key, value]) {
|
|
54
|
+
return `${key}=${encodeValue(value)}`;
|
|
55
|
+
}
|
|
56
|
+
function encodeContextObject(context) {
|
|
57
|
+
return Object.entries(context).map(encodeObjectContextEntry).join("&");
|
|
58
|
+
}
|
|
59
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
60
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
61
|
+
const message = messageFormatString.replace(
|
|
62
|
+
/(?<!\\)\$(\w+)/g,
|
|
63
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
64
|
+
);
|
|
65
|
+
return message;
|
|
66
|
+
}
|
|
67
|
+
function getErrorMessage(code, context = {}) {
|
|
68
|
+
if (__DEV__) {
|
|
69
|
+
return getHumanReadableErrorMessage(code, context);
|
|
70
|
+
} else {
|
|
71
|
+
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode ${code}`;
|
|
72
|
+
if (Object.keys(context).length) {
|
|
73
|
+
decodingAdviceMessage += ` $"${encodeContextObject(context)}"`;
|
|
74
|
+
}
|
|
75
|
+
return `${decodingAdviceMessage}\``;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/error.ts
|
|
80
|
+
function isSolanaError(e, code) {
|
|
81
|
+
const isSolanaError2 = e instanceof Error && e.name === "SolanaError";
|
|
82
|
+
if (isSolanaError2) {
|
|
83
|
+
if (code !== void 0) {
|
|
84
|
+
return e.context.__code === code;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
var SolanaError = class extends Error {
|
|
91
|
+
context;
|
|
92
|
+
constructor(...[code, context]) {
|
|
93
|
+
const message = getErrorMessage(code, context);
|
|
94
|
+
super(message);
|
|
95
|
+
this.context = {
|
|
96
|
+
__code: code,
|
|
97
|
+
...context
|
|
98
|
+
};
|
|
99
|
+
this.name = "SolanaError";
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED;
|
|
104
|
+
exports.SOLANA_ERROR__INVALID_KEYPAIR_BYTES = SOLANA_ERROR__INVALID_KEYPAIR_BYTES;
|
|
105
|
+
exports.SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;
|
|
106
|
+
exports.SOLANA_ERROR__NONCE_INVALID = SOLANA_ERROR__NONCE_INVALID;
|
|
107
|
+
exports.SOLANA_ERROR__RPC_INTEGER_OVERFLOW = SOLANA_ERROR__RPC_INTEGER_OVERFLOW;
|
|
108
|
+
exports.SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES;
|
|
109
|
+
exports.SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE;
|
|
110
|
+
exports.SolanaError = SolanaError;
|
|
111
|
+
exports.isSolanaError = isSolanaError;
|
|
112
|
+
//# sourceMappingURL=out.js.map
|
|
113
|
+
//# sourceMappingURL=index.node.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/codes.ts","../src/messages.ts","../src/message-formatter.ts","../src/error.ts"],"names":["isSolanaError"],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACOhG,IAAM,+CAA+C;AACrD,IAAM,qDAAqD;AAC3D,IAAM,qCAAqC;AAC3C,IAAM,sCAAsC;AAC5C,IAAM,sCAAsC;AAC5C,IAAM,8BAA8B;AACpC,IAAM,wCAAwC;;;ACI9C,IAAM,sBAIR;AAAA,EACD,CAAC,mCAAmC,GAChC;AAAA,EACJ,CAAC,mCAAmC,GAAG;AAAA,EACvC,CAAC,qCAAqC,GAAG;AAAA,EACzC,CAAC,2BAA2B,GACxB;AAAA,EACJ,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;AClCA,SAAS,YAAY,OAAwB;AACzC,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB;AAAA;AAAA,MACc,QACV,MACK;AAAA,QAAI,aACD,OAAO,YAAY,WACb,mBAAmB,IAAI,QAAQ,QAAQ,MAAM,KAAK,CAAC,GAAG,IACtD,YAAY,OAAO;AAAA,MAC7B,EACC;AAAA;AAAA,QAAgB;AAAA,MAAQ;AAAA,MACnB;AAAA;AAAA,EAElB,WAAW,OAAO,UAAU,UAAU;AAClC,WAAO,GAAG,KAAK;AAAA,EACnB,OAAO;AACH,WAAO;AAAA,MACH;AAAA,QACI,OAAO,eAAe,KAAK,MAAM;AAAA;AAAA;AAAA,UAG3B,EAAE,GAAI,MAAiB;AAAA,YACvB;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,SAAS,yBAAyB,CAAC,KAAK,KAAK,GAAiD;AAC1F,SAAO,GAAG,GAAG,IAAI,YAAY,KAAK,CAAC;AACvC;AAEA,SAAS,oBAAoB,SAAiB;AAC1C,SAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,wBAAwB,EAAE,KAAK,GAAG;AACzE;AAEO,SAAS,6BACZ,MACA,UAAkB,CAAC,GACb;AACN,QAAM,sBAAsB,oBAAoB,IAAI;AACpD,QAAM,UAAU,oBAAoB;AAAA,IAAQ;AAAA,IAAmB,CAAC,WAAW,iBACvE,gBAAgB,UAAU,GAAG,QAAQ,YAAoC,CAAC,KAAK;AAAA,EACnF;AACA,SAAO;AACX;AAEO,SAAS,gBAAoD,MAAkB,UAAkB,CAAC,GAAW;AAChH,MAAI,SAAS;AACT,WAAO,6BAA6B,MAAM,OAAO;AAAA,EACrD,OAAO;AACH,QAAI,wBAAwB,iBAAiB,IAAI,8DAA8D,IAAI;AACnH,QAAI,OAAO,KAAK,OAAO,EAAE,QAAQ;AAM7B,+BAAyB,MAAM,oBAAoB,OAAO,CAAC;AAAA,IAC/D;AACA,WAAO,GAAG,qBAAqB;AAAA,EACnC;AACJ;;;AC7DO,SAAS,cACZ,GACA,MAC4B;AAC5B,QAAMA,iBAAgB,aAAa,SAAS,EAAE,SAAS;AACvD,MAAIA,gBAAe;AACf,QAAI,SAAS,QAAW;AACpB,aAAQ,EAA8B,QAAQ,WAAW;AAAA,IAC7D;AACA,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAQO,IAAM,cAAN,cAAgF,MAAM;AAAA,EAChF;AAAA,EACT,eACO,CAAC,MAAM,OAAO,GAGnB;AACE,UAAM,UAAU,gBAAgB,MAAM,OAAO;AAC7C,UAAM,OAAO;AACb,SAAK,UAAU;AAAA,MACX,QAAQ;AAAA,MACR,GAAG;AAAA,IACP;AAGA,SAAK,OAAO;AAAA,EAChB;AACJ","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't remove error codes\n * - Don't change or reorder error codes.\n */\nexport const SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1 as const;\nexport const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2 as const;\nexport const SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3 as const;\nexport const SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4 as const;\nexport const SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5 as const;\nexport const SOLANA_ERROR__NONCE_INVALID = 6 as const;\nexport const SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7 as const;\n\n/**\n * A union of every Solana error code\n *\n * You might be wondering why this is not a TypeScript enum or const enum.\n *\n * One of the goals of this library is to enable people to use some or none of it without having to\n * bundle all of it.\n *\n * If we made the set of error codes an enum then anyone who imported it (even if to only use a\n * single error code) would be forced to bundle every code and its label.\n *\n * Const enums appear to solve this problem by letting the compiler inline only the codes that are\n * actually used. Unfortunately exporting ambient (const) enums from a library like `@solana/errors`\n * is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850\n */\nexport type SolanaErrorCode =\n | typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES\n | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE\n | typeof SOLANA_ERROR__RPC_INTEGER_OVERFLOW\n | typeof SOLANA_ERROR__INVALID_KEYPAIR_BYTES\n | typeof SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED\n | typeof SOLANA_ERROR__NONCE_INVALID\n | typeof SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;\n","import {\n SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED,\n SOLANA_ERROR__INVALID_KEYPAIR_BYTES,\n SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,\n SOLANA_ERROR__NONCE_INVALID,\n SOLANA_ERROR__RPC_INTEGER_OVERFLOW,\n SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES,\n SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE,\n SolanaErrorCode,\n} from './codes';\n\n/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't change the meaning of an error message.\n */\nexport const SolanaErrorMessages: Readonly<{\n // This type makes this data structure exhaustive with respect to `SolanaErrorCode`.\n // TypeScript will fail to build this project if add an error code without a message.\n [P in SolanaErrorCode]: string;\n}> = {\n [SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]:\n 'The network has progressed past the last block for which this transaction could have been committed.',\n [SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: 'Key pair bytes must be of length 64, got $byteLength.',\n [SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: 'No nonce account could be found at address `$nonceAccountAddress`',\n [SOLANA_ERROR__NONCE_INVALID]:\n 'The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`',\n [SOLANA_ERROR__RPC_INTEGER_OVERFLOW]:\n 'The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was ' +\n '`$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds ' +\n '`Number.MAX_SAFE_INTEGER`.',\n [SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: 'Transaction is missing signatures for addresses: $addresses.',\n [SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]:\n \"Could not determine this transaction's signature. Make sure that the transaction has \" +\n 'been signed by its fee payer.',\n};\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorMessages } from './messages';\n\nfunction encodeValue(value: unknown): string {\n if (Array.isArray(value)) {\n return (\n /* \"[\" */ '%5B' +\n value\n .map(element =>\n typeof element === 'string'\n ? encodeURIComponent(`\"${element.replace(/\"/g, '\\\\\"')}\"`)\n : encodeValue(element),\n )\n .join(/* \", \" */ '%2C%20') +\n /* \"]\" */ '%5D'\n );\n } else if (typeof value === 'bigint') {\n return `${value}n`;\n } else {\n return encodeURIComponent(\n String(\n Object.getPrototypeOf(value) === null\n ? // Plain objects with no protoype don't have a `toString` method.\n // Convert them before stringifying them.\n { ...(value as object) }\n : value,\n ),\n );\n }\n}\n\nfunction encodeObjectContextEntry([key, value]: [string, unknown]): `${typeof key}=${string}` {\n return `${key}=${encodeValue(value)}`;\n}\n\nfunction encodeContextObject(context: object) {\n return Object.entries(context).map(encodeObjectContextEntry).join('&');\n}\n\nexport function getHumanReadableErrorMessage<TErrorCode extends SolanaErrorCode>(\n code: TErrorCode,\n context: object = {},\n): string {\n const messageFormatString = SolanaErrorMessages[code];\n const message = messageFormatString.replace(/(?<!\\\\)\\$(\\w+)/g, (substring, variableName) =>\n variableName in context ? `${context[variableName as keyof typeof context]}` : substring,\n );\n return message;\n}\n\nexport function getErrorMessage<TErrorCode extends SolanaErrorCode>(code: TErrorCode, context: object = {}): string {\n if (__DEV__) {\n return getHumanReadableErrorMessage(code, context);\n } else {\n let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \\`npx @solana/errors decode ${code}`;\n if (Object.keys(context).length) {\n /**\n * DANGER: Be sure that the shell command is escaped in such a way that makes it\n * impossible for someone to craft malicious context values that would result in\n * an exploit against anyone who bindly copy/pastes it into their terminal.\n */\n decodingAdviceMessage += ` $\"${encodeContextObject(context)}\"`;\n }\n return `${decodingAdviceMessage}\\``;\n }\n}\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorContext } from './context';\nimport { getErrorMessage } from './message-formatter';\n\nexport function isSolanaError<TErrorCode extends SolanaErrorCode>(\n e: unknown,\n code?: TErrorCode,\n): e is SolanaError<TErrorCode> {\n const isSolanaError = e instanceof Error && e.name === 'SolanaError';\n if (isSolanaError) {\n if (code !== undefined) {\n return (e as SolanaError<TErrorCode>).context.__code === code;\n }\n return true;\n }\n return false;\n}\n\ntype SolanaErrorCodedContext = Readonly<{\n [P in SolanaErrorCode]: (SolanaErrorContext[P] extends undefined ? object : SolanaErrorContext[P]) & {\n __code: P;\n };\n}>;\n\nexport class SolanaError<TErrorCode extends SolanaErrorCode = SolanaErrorCode> extends Error {\n readonly context: SolanaErrorCodedContext[TErrorCode];\n constructor(\n ...[code, context]: SolanaErrorContext[TErrorCode] extends undefined\n ? [code: TErrorCode]\n : [code: TErrorCode, context: SolanaErrorContext[TErrorCode]]\n ) {\n const message = getErrorMessage(code, context);\n super(message);\n this.context = {\n __code: code,\n ...context,\n } as SolanaErrorCodedContext[TErrorCode];\n // This is necessary so that `isSolanaError()` can identify a `SolanaError` without having\n // to import the class for use in an `instanceof` check.\n this.name = 'SolanaError';\n }\n}\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// ../build-scripts/env-shim.ts
|
|
2
|
+
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
3
|
+
|
|
4
|
+
// src/codes.ts
|
|
5
|
+
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
6
|
+
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
7
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
8
|
+
var SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4;
|
|
9
|
+
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5;
|
|
10
|
+
var SOLANA_ERROR__NONCE_INVALID = 6;
|
|
11
|
+
var SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7;
|
|
12
|
+
|
|
13
|
+
// src/messages.ts
|
|
14
|
+
var SolanaErrorMessages = {
|
|
15
|
+
[SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]: "The network has progressed past the last block for which this transaction could have been committed.",
|
|
16
|
+
[SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: "Key pair bytes must be of length 64, got $byteLength.",
|
|
17
|
+
[SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: "No nonce account could be found at address `$nonceAccountAddress`",
|
|
18
|
+
[SOLANA_ERROR__NONCE_INVALID]: "The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`",
|
|
19
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: "The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was `$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds `Number.MAX_SAFE_INTEGER`.",
|
|
20
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses.",
|
|
21
|
+
[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."
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/message-formatter.ts
|
|
25
|
+
function encodeValue(value) {
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return (
|
|
28
|
+
/* "[" */
|
|
29
|
+
"%5B" + value.map(
|
|
30
|
+
(element) => typeof element === "string" ? encodeURIComponent(`"${element.replace(/"/g, '\\"')}"`) : encodeValue(element)
|
|
31
|
+
).join(
|
|
32
|
+
/* ", " */
|
|
33
|
+
"%2C%20"
|
|
34
|
+
) + /* "]" */
|
|
35
|
+
"%5D"
|
|
36
|
+
);
|
|
37
|
+
} else if (typeof value === "bigint") {
|
|
38
|
+
return `${value}n`;
|
|
39
|
+
} else {
|
|
40
|
+
return encodeURIComponent(
|
|
41
|
+
String(
|
|
42
|
+
Object.getPrototypeOf(value) === null ? (
|
|
43
|
+
// Plain objects with no protoype don't have a `toString` method.
|
|
44
|
+
// Convert them before stringifying them.
|
|
45
|
+
{ ...value }
|
|
46
|
+
) : value
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function encodeObjectContextEntry([key, value]) {
|
|
52
|
+
return `${key}=${encodeValue(value)}`;
|
|
53
|
+
}
|
|
54
|
+
function encodeContextObject(context) {
|
|
55
|
+
return Object.entries(context).map(encodeObjectContextEntry).join("&");
|
|
56
|
+
}
|
|
57
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
58
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
59
|
+
const message = messageFormatString.replace(
|
|
60
|
+
/(?<!\\)\$(\w+)/g,
|
|
61
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
62
|
+
);
|
|
63
|
+
return message;
|
|
64
|
+
}
|
|
65
|
+
function getErrorMessage(code, context = {}) {
|
|
66
|
+
if (__DEV__) {
|
|
67
|
+
return getHumanReadableErrorMessage(code, context);
|
|
68
|
+
} else {
|
|
69
|
+
let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode ${code}`;
|
|
70
|
+
if (Object.keys(context).length) {
|
|
71
|
+
decodingAdviceMessage += ` $"${encodeContextObject(context)}"`;
|
|
72
|
+
}
|
|
73
|
+
return `${decodingAdviceMessage}\``;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/error.ts
|
|
78
|
+
function isSolanaError(e, code) {
|
|
79
|
+
const isSolanaError2 = e instanceof Error && e.name === "SolanaError";
|
|
80
|
+
if (isSolanaError2) {
|
|
81
|
+
if (code !== void 0) {
|
|
82
|
+
return e.context.__code === code;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
var SolanaError = class extends Error {
|
|
89
|
+
context;
|
|
90
|
+
constructor(...[code, context]) {
|
|
91
|
+
const message = getErrorMessage(code, context);
|
|
92
|
+
super(message);
|
|
93
|
+
this.context = {
|
|
94
|
+
__code: code,
|
|
95
|
+
...context
|
|
96
|
+
};
|
|
97
|
+
this.name = "SolanaError";
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED, SOLANA_ERROR__INVALID_KEYPAIR_BYTES, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND, SOLANA_ERROR__NONCE_INVALID, SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
102
|
+
//# sourceMappingURL=out.js.map
|
|
103
|
+
//# sourceMappingURL=index.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/codes.ts","../src/messages.ts","../src/message-formatter.ts","../src/error.ts"],"names":["isSolanaError"],"mappings":";AACO,IAAM,UAA2B,uBAAO,QAAgB,KAAU,EAAE,aAAa,eAAe;;;ACOhG,IAAM,+CAA+C;AACrD,IAAM,qDAAqD;AAC3D,IAAM,qCAAqC;AAC3C,IAAM,sCAAsC;AAC5C,IAAM,sCAAsC;AAC5C,IAAM,8BAA8B;AACpC,IAAM,wCAAwC;;;ACI9C,IAAM,sBAIR;AAAA,EACD,CAAC,mCAAmC,GAChC;AAAA,EACJ,CAAC,mCAAmC,GAAG;AAAA,EACvC,CAAC,qCAAqC,GAAG;AAAA,EACzC,CAAC,2BAA2B,GACxB;AAAA,EACJ,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;AClCA,SAAS,YAAY,OAAwB;AACzC,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB;AAAA;AAAA,MACc,QACV,MACK;AAAA,QAAI,aACD,OAAO,YAAY,WACb,mBAAmB,IAAI,QAAQ,QAAQ,MAAM,KAAK,CAAC,GAAG,IACtD,YAAY,OAAO;AAAA,MAC7B,EACC;AAAA;AAAA,QAAgB;AAAA,MAAQ;AAAA,MACnB;AAAA;AAAA,EAElB,WAAW,OAAO,UAAU,UAAU;AAClC,WAAO,GAAG,KAAK;AAAA,EACnB,OAAO;AACH,WAAO;AAAA,MACH;AAAA,QACI,OAAO,eAAe,KAAK,MAAM;AAAA;AAAA;AAAA,UAG3B,EAAE,GAAI,MAAiB;AAAA,YACvB;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,SAAS,yBAAyB,CAAC,KAAK,KAAK,GAAiD;AAC1F,SAAO,GAAG,GAAG,IAAI,YAAY,KAAK,CAAC;AACvC;AAEA,SAAS,oBAAoB,SAAiB;AAC1C,SAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,wBAAwB,EAAE,KAAK,GAAG;AACzE;AAEO,SAAS,6BACZ,MACA,UAAkB,CAAC,GACb;AACN,QAAM,sBAAsB,oBAAoB,IAAI;AACpD,QAAM,UAAU,oBAAoB;AAAA,IAAQ;AAAA,IAAmB,CAAC,WAAW,iBACvE,gBAAgB,UAAU,GAAG,QAAQ,YAAoC,CAAC,KAAK;AAAA,EACnF;AACA,SAAO;AACX;AAEO,SAAS,gBAAoD,MAAkB,UAAkB,CAAC,GAAW;AAChH,MAAI,SAAS;AACT,WAAO,6BAA6B,MAAM,OAAO;AAAA,EACrD,OAAO;AACH,QAAI,wBAAwB,iBAAiB,IAAI,8DAA8D,IAAI;AACnH,QAAI,OAAO,KAAK,OAAO,EAAE,QAAQ;AAM7B,+BAAyB,MAAM,oBAAoB,OAAO,CAAC;AAAA,IAC/D;AACA,WAAO,GAAG,qBAAqB;AAAA,EACnC;AACJ;;;AC7DO,SAAS,cACZ,GACA,MAC4B;AAC5B,QAAMA,iBAAgB,aAAa,SAAS,EAAE,SAAS;AACvD,MAAIA,gBAAe;AACf,QAAI,SAAS,QAAW;AACpB,aAAQ,EAA8B,QAAQ,WAAW;AAAA,IAC7D;AACA,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAQO,IAAM,cAAN,cAAgF,MAAM;AAAA,EAChF;AAAA,EACT,eACO,CAAC,MAAM,OAAO,GAGnB;AACE,UAAM,UAAU,gBAAgB,MAAM,OAAO;AAC7C,UAAM,OAAO;AACb,SAAK,UAAU;AAAA,MACX,QAAQ;AAAA,MACR,GAAG;AAAA,IACP;AAGA,SAAK,OAAO;AAAA,EAChB;AACJ","sourcesContent":["// Clever obfuscation to prevent the build system from inlining the value of `NODE_ENV`\nexport const __DEV__ = /* @__PURE__ */ (() => (process as any)['en' + 'v'].NODE_ENV === 'development')();\n","/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't remove error codes\n * - Don't change or reorder error codes.\n */\nexport const SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1 as const;\nexport const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2 as const;\nexport const SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3 as const;\nexport const SOLANA_ERROR__INVALID_KEYPAIR_BYTES = 4 as const;\nexport const SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 5 as const;\nexport const SOLANA_ERROR__NONCE_INVALID = 6 as const;\nexport const SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND = 7 as const;\n\n/**\n * A union of every Solana error code\n *\n * You might be wondering why this is not a TypeScript enum or const enum.\n *\n * One of the goals of this library is to enable people to use some or none of it without having to\n * bundle all of it.\n *\n * If we made the set of error codes an enum then anyone who imported it (even if to only use a\n * single error code) would be forced to bundle every code and its label.\n *\n * Const enums appear to solve this problem by letting the compiler inline only the codes that are\n * actually used. Unfortunately exporting ambient (const) enums from a library like `@solana/errors`\n * is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850\n */\nexport type SolanaErrorCode =\n | typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES\n | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE\n | typeof SOLANA_ERROR__RPC_INTEGER_OVERFLOW\n | typeof SOLANA_ERROR__INVALID_KEYPAIR_BYTES\n | typeof SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED\n | typeof SOLANA_ERROR__NONCE_INVALID\n | typeof SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;\n","import {\n SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED,\n SOLANA_ERROR__INVALID_KEYPAIR_BYTES,\n SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,\n SOLANA_ERROR__NONCE_INVALID,\n SOLANA_ERROR__RPC_INTEGER_OVERFLOW,\n SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES,\n SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE,\n SolanaErrorCode,\n} from './codes';\n\n/**\n * To add a new error, follow the instructions at\n * https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error\n *\n * WARNING:\n * - Don't change the meaning of an error message.\n */\nexport const SolanaErrorMessages: Readonly<{\n // This type makes this data structure exhaustive with respect to `SolanaErrorCode`.\n // TypeScript will fail to build this project if add an error code without a message.\n [P in SolanaErrorCode]: string;\n}> = {\n [SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]:\n 'The network has progressed past the last block for which this transaction could have been committed.',\n [SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: 'Key pair bytes must be of length 64, got $byteLength.',\n [SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: 'No nonce account could be found at address `$nonceAccountAddress`',\n [SOLANA_ERROR__NONCE_INVALID]:\n 'The nonce `$expectedNonceValue` is no longer valid. It has advanced to `$actualNonceValue`',\n [SOLANA_ERROR__RPC_INTEGER_OVERFLOW]:\n 'The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was ' +\n '`$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds ' +\n '`Number.MAX_SAFE_INTEGER`.',\n [SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: 'Transaction is missing signatures for addresses: $addresses.',\n [SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]:\n \"Could not determine this transaction's signature. Make sure that the transaction has \" +\n 'been signed by its fee payer.',\n};\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorMessages } from './messages';\n\nfunction encodeValue(value: unknown): string {\n if (Array.isArray(value)) {\n return (\n /* \"[\" */ '%5B' +\n value\n .map(element =>\n typeof element === 'string'\n ? encodeURIComponent(`\"${element.replace(/\"/g, '\\\\\"')}\"`)\n : encodeValue(element),\n )\n .join(/* \", \" */ '%2C%20') +\n /* \"]\" */ '%5D'\n );\n } else if (typeof value === 'bigint') {\n return `${value}n`;\n } else {\n return encodeURIComponent(\n String(\n Object.getPrototypeOf(value) === null\n ? // Plain objects with no protoype don't have a `toString` method.\n // Convert them before stringifying them.\n { ...(value as object) }\n : value,\n ),\n );\n }\n}\n\nfunction encodeObjectContextEntry([key, value]: [string, unknown]): `${typeof key}=${string}` {\n return `${key}=${encodeValue(value)}`;\n}\n\nfunction encodeContextObject(context: object) {\n return Object.entries(context).map(encodeObjectContextEntry).join('&');\n}\n\nexport function getHumanReadableErrorMessage<TErrorCode extends SolanaErrorCode>(\n code: TErrorCode,\n context: object = {},\n): string {\n const messageFormatString = SolanaErrorMessages[code];\n const message = messageFormatString.replace(/(?<!\\\\)\\$(\\w+)/g, (substring, variableName) =>\n variableName in context ? `${context[variableName as keyof typeof context]}` : substring,\n );\n return message;\n}\n\nexport function getErrorMessage<TErrorCode extends SolanaErrorCode>(code: TErrorCode, context: object = {}): string {\n if (__DEV__) {\n return getHumanReadableErrorMessage(code, context);\n } else {\n let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \\`npx @solana/errors decode ${code}`;\n if (Object.keys(context).length) {\n /**\n * DANGER: Be sure that the shell command is escaped in such a way that makes it\n * impossible for someone to craft malicious context values that would result in\n * an exploit against anyone who bindly copy/pastes it into their terminal.\n */\n decodingAdviceMessage += ` $\"${encodeContextObject(context)}\"`;\n }\n return `${decodingAdviceMessage}\\``;\n }\n}\n","import { SolanaErrorCode } from './codes';\nimport { SolanaErrorContext } from './context';\nimport { getErrorMessage } from './message-formatter';\n\nexport function isSolanaError<TErrorCode extends SolanaErrorCode>(\n e: unknown,\n code?: TErrorCode,\n): e is SolanaError<TErrorCode> {\n const isSolanaError = e instanceof Error && e.name === 'SolanaError';\n if (isSolanaError) {\n if (code !== undefined) {\n return (e as SolanaError<TErrorCode>).context.__code === code;\n }\n return true;\n }\n return false;\n}\n\ntype SolanaErrorCodedContext = Readonly<{\n [P in SolanaErrorCode]: (SolanaErrorContext[P] extends undefined ? object : SolanaErrorContext[P]) & {\n __code: P;\n };\n}>;\n\nexport class SolanaError<TErrorCode extends SolanaErrorCode = SolanaErrorCode> extends Error {\n readonly context: SolanaErrorCodedContext[TErrorCode];\n constructor(\n ...[code, context]: SolanaErrorContext[TErrorCode] extends undefined\n ? [code: TErrorCode]\n : [code: TErrorCode, context: SolanaErrorContext[TErrorCode]]\n ) {\n const message = getErrorMessage(code, context);\n super(message);\n this.context = {\n __code: code,\n ...context,\n } as SolanaErrorCodedContext[TErrorCode];\n // This is necessary so that `isSolanaError()` can identify a `SolanaError` without having\n // to import the class for use in an `instanceof` check.\n this.name = 'SolanaError';\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* To add a new error, follow the instructions at
|
|
3
|
+
* https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error
|
|
4
|
+
*
|
|
5
|
+
* WARNING:
|
|
6
|
+
* - Don't remove error codes
|
|
7
|
+
* - Don't change or reorder error codes.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES: 1;
|
|
10
|
+
export declare const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE: 2;
|
|
11
|
+
export declare const SOLANA_ERROR__RPC_INTEGER_OVERFLOW: 3;
|
|
12
|
+
export declare const SOLANA_ERROR__INVALID_KEYPAIR_BYTES: 4;
|
|
13
|
+
export declare const SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED: 5;
|
|
14
|
+
export declare const SOLANA_ERROR__NONCE_INVALID: 6;
|
|
15
|
+
export declare const SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND: 7;
|
|
16
|
+
/**
|
|
17
|
+
* A union of every Solana error code
|
|
18
|
+
*
|
|
19
|
+
* You might be wondering why this is not a TypeScript enum or const enum.
|
|
20
|
+
*
|
|
21
|
+
* One of the goals of this library is to enable people to use some or none of it without having to
|
|
22
|
+
* bundle all of it.
|
|
23
|
+
*
|
|
24
|
+
* If we made the set of error codes an enum then anyone who imported it (even if to only use a
|
|
25
|
+
* single error code) would be forced to bundle every code and its label.
|
|
26
|
+
*
|
|
27
|
+
* Const enums appear to solve this problem by letting the compiler inline only the codes that are
|
|
28
|
+
* actually used. Unfortunately exporting ambient (const) enums from a library like `@solana/errors`
|
|
29
|
+
* is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850
|
|
30
|
+
*/
|
|
31
|
+
export type SolanaErrorCode = typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE | typeof SOLANA_ERROR__RPC_INTEGER_OVERFLOW | typeof SOLANA_ERROR__INVALID_KEYPAIR_BYTES | typeof SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED | typeof SOLANA_ERROR__NONCE_INVALID | typeof SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND;
|
|
32
|
+
//# sourceMappingURL=codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/codes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,4CAA4C,GAAa,CAAC;AACvE,eAAO,MAAM,kDAAkD,GAAa,CAAC;AAC7E,eAAO,MAAM,kCAAkC,GAAa,CAAC;AAC7D,eAAO,MAAM,mCAAmC,GAAa,CAAC;AAC9D,eAAO,MAAM,mCAAmC,GAAa,CAAC;AAC9D,eAAO,MAAM,2BAA2B,GAAa,CAAC;AACtD,eAAO,MAAM,qCAAqC,GAAa,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GACrB,OAAO,4CAA4C,GACnD,OAAO,kDAAkD,GACzD,OAAO,kCAAkC,GACzC,OAAO,mCAAmC,GAC1C,OAAO,mCAAmC,GAC1C,OAAO,2BAA2B,GAClC,OAAO,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED, SOLANA_ERROR__INVALID_KEYPAIR_BYTES, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND, SOLANA_ERROR__NONCE_INVALID, SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SolanaErrorCode } from './codes.js';
|
|
2
|
+
export type DefaultUnspecifiedErrorContextToUndefined<T> = {
|
|
3
|
+
[P in SolanaErrorCode]: P extends keyof T ? T[P] : undefined;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* To add a new error, follow the instructions at
|
|
7
|
+
* https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error
|
|
8
|
+
*
|
|
9
|
+
* WARNING:
|
|
10
|
+
* - Don't change or remove members of an error's context.
|
|
11
|
+
*/
|
|
12
|
+
export type SolanaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
|
|
13
|
+
[SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED]: {
|
|
14
|
+
currentBlockHeight: bigint;
|
|
15
|
+
lastValidBlockHeight: bigint;
|
|
16
|
+
};
|
|
17
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: {
|
|
18
|
+
addresses: string[];
|
|
19
|
+
};
|
|
20
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: {
|
|
21
|
+
argumentLabel: string;
|
|
22
|
+
keyPath: readonly (string | number | symbol)[];
|
|
23
|
+
methodName: string;
|
|
24
|
+
optionalPathLabel: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
value: bigint;
|
|
27
|
+
};
|
|
28
|
+
[SOLANA_ERROR__INVALID_KEYPAIR_BYTES]: {
|
|
29
|
+
byteLength: number;
|
|
30
|
+
};
|
|
31
|
+
[SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND]: {
|
|
32
|
+
nonceAccountAddress: string;
|
|
33
|
+
};
|
|
34
|
+
[SOLANA_ERROR__NONCE_INVALID]: {
|
|
35
|
+
actualNonceValue: string;
|
|
36
|
+
expectedNonceValue: string;
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mCAAmC,EACnC,mCAAmC,EACnC,qCAAqC,EACrC,2BAA2B,EAC3B,kCAAkC,EAClC,4CAA4C,EAC5C,eAAe,EAClB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,yCAAyC,CAAC,CAAC,IAAI;KACtD,CAAC,IAAI,eAAe,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAC/D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,yCAAyC,CAAC;IACvE,CAAC,mCAAmC,CAAC,EAAE;QACnC,kBAAkB,EAAE,MAAM,CAAC;QAC3B,oBAAoB,EAAE,MAAM,CAAC;KAChC,CAAC;IACF,CAAC,4CAA4C,CAAC,EAAE;QAC5C,SAAS,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;IACF,CAAC,kCAAkC,CAAC,EAAE;QAClC,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;QAC/C,UAAU,EAAE,MAAM,CAAC;QACnB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,CAAC,mCAAmC,CAAC,EAAE;QACnC,UAAU,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,CAAC,qCAAqC,CAAC,EAAE;QACrC,mBAAmB,EAAE,MAAM,CAAC;KAC/B,CAAC;IACF,CAAC,2BAA2B,CAAC,EAAE;QAC3B,gBAAgB,EAAE,MAAM,CAAC;QACzB,kBAAkB,EAAE,MAAM,CAAC;KAC9B,CAAC;CACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SolanaErrorCode } from './codes.js';
|
|
2
|
+
import { SolanaErrorContext } from './context.js';
|
|
3
|
+
export declare function isSolanaError<TErrorCode extends SolanaErrorCode>(e: unknown, code?: TErrorCode): e is SolanaError<TErrorCode>;
|
|
4
|
+
type SolanaErrorCodedContext = Readonly<{
|
|
5
|
+
[P in SolanaErrorCode]: (SolanaErrorContext[P] extends undefined ? object : SolanaErrorContext[P]) & {
|
|
6
|
+
__code: P;
|
|
7
|
+
};
|
|
8
|
+
}>;
|
|
9
|
+
export declare class SolanaError<TErrorCode extends SolanaErrorCode = SolanaErrorCode> extends Error {
|
|
10
|
+
readonly context: SolanaErrorCodedContext[TErrorCode];
|
|
11
|
+
constructor(...[code, context]: SolanaErrorContext[TErrorCode] extends undefined ? [code: TErrorCode] : [code: TErrorCode, context: SolanaErrorContext[TErrorCode]]);
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG/C,wBAAgB,aAAa,CAAC,UAAU,SAAS,eAAe,EAC5D,CAAC,EAAE,OAAO,EACV,IAAI,CAAC,EAAE,UAAU,GAClB,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,CAS9B;AAED,KAAK,uBAAuB,GAAG,QAAQ,CAAC;KACnC,CAAC,IAAI,eAAe,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG;QACjG,MAAM,EAAE,CAAC,CAAC;KACb;CACJ,CAAC,CAAC;AAEH,qBAAa,WAAW,CAAC,UAAU,SAAS,eAAe,GAAG,eAAe,CAAE,SAAQ,KAAK;IACxF,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC;gBAElD,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,SAAS,SAAS,GAC9D,CAAC,IAAI,EAAE,UAAU,CAAC,GAClB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;CAYxE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SolanaErrorCode } from './codes.js';
|
|
2
|
+
export declare function getHumanReadableErrorMessage<TErrorCode extends SolanaErrorCode>(code: TErrorCode, context?: object): string;
|
|
3
|
+
export declare function getErrorMessage<TErrorCode extends SolanaErrorCode>(code: TErrorCode, context?: object): string;
|
|
4
|
+
//# sourceMappingURL=message-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-formatter.d.ts","sourceRoot":"","sources":["../../src/message-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAuC1C,wBAAgB,4BAA4B,CAAC,UAAU,SAAS,eAAe,EAC3E,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE,MAAW,GACrB,MAAM,CAMR;AAED,wBAAgB,eAAe,CAAC,UAAU,SAAS,eAAe,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,MAAW,GAAG,MAAM,CAelH"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SolanaErrorCode } from './codes.js';
|
|
2
|
+
/**
|
|
3
|
+
* To add a new error, follow the instructions at
|
|
4
|
+
* https://github.com/solana-labs/solana-web3.js/tree/master/packages/error#adding-a-new-error
|
|
5
|
+
*
|
|
6
|
+
* WARNING:
|
|
7
|
+
* - Don't change the meaning of an error message.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SolanaErrorMessages: Readonly<{
|
|
10
|
+
[P in SolanaErrorCode]: string;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAQH,eAAe,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC;KAGtC,CAAC,IAAI,eAAe,GAAG,MAAM;CACjC,CAeA,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana/errors",
|
|
3
|
+
"version": "2.0.0-experimental.021706b",
|
|
4
|
+
"description": "Throw, identify, and decode Solana JavaScript errors",
|
|
5
|
+
"exports": {
|
|
6
|
+
"browser": {
|
|
7
|
+
"import": "./dist/index.browser.js",
|
|
8
|
+
"require": "./dist/index.browser.cjs"
|
|
9
|
+
},
|
|
10
|
+
"node": {
|
|
11
|
+
"import": "./dist/index.node.js",
|
|
12
|
+
"require": "./dist/index.node.cjs"
|
|
13
|
+
},
|
|
14
|
+
"react-native": "./dist/index.native.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"browser": {
|
|
18
|
+
"./dist/index.node.cjs": "./dist/index.browser.cjs",
|
|
19
|
+
"./dist/index.node.js": "./dist/index.browser.js"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.node.cjs",
|
|
22
|
+
"module": "./dist/index.node.js",
|
|
23
|
+
"react-native": "./dist/index.native.js",
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"files": [
|
|
27
|
+
"./dist/"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"keywords": [
|
|
31
|
+
"blockchain",
|
|
32
|
+
"solana",
|
|
33
|
+
"web3"
|
|
34
|
+
],
|
|
35
|
+
"bin": "./bin/cli.js",
|
|
36
|
+
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/solana-labs/solana-web3.js"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "http://github.com/solana-labs/solana-web3.js/issues"
|
|
44
|
+
},
|
|
45
|
+
"browserslist": [
|
|
46
|
+
"supports bigint and not dead",
|
|
47
|
+
"maintained node versions"
|
|
48
|
+
],
|
|
49
|
+
"engine": {
|
|
50
|
+
"node": ">=17.4"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"chalk": "^5.3.0",
|
|
54
|
+
"commander": "^11.1.0"
|
|
55
|
+
},
|
|
56
|
+
"bundlewatch": {
|
|
57
|
+
"defaultCompression": "gzip",
|
|
58
|
+
"files": [
|
|
59
|
+
{
|
|
60
|
+
"path": "./dist/index*.js"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts && tsup src/cli.ts --format esm",
|
|
66
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
|
|
67
|
+
"dev": "jest -c node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
68
|
+
"publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag experimental --access public --no-git-checks",
|
|
69
|
+
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
|
|
70
|
+
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
71
|
+
"test:lint": "jest -c node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
72
|
+
"test:prettier": "jest -c node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
73
|
+
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
74
|
+
"test:treeshakability:native": "agadoo dist/index.native.js",
|
|
75
|
+
"test:treeshakability:node": "agadoo dist/index.node.js",
|
|
76
|
+
"test:typecheck": "tsc --noEmit",
|
|
77
|
+
"test:unit:browser": "jest -c node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
78
|
+
"test:unit:node": "jest -c node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
79
|
+
}
|
|
80
|
+
}
|