@solana/errors 2.0.0-experimental.6cea83c → 2.0.0-experimental.dd2096e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +7 -0
- package/dist/cli.js +64 -0
- package/dist/index.browser.cjs +3 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +3 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +3 -1
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +3 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +3 -1
- package/dist/index.node.js.map +1 -1
- package/dist/types/codes.d.ts +2 -1
- package/dist/types/codes.d.ts.map +1 -1
- package/dist/types/context.d.ts +9 -1
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/messages.d.ts.map +1 -1
- package/package.json +98 -98
- package/bin/cli.ts +0 -55
package/bin/cli.js
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
|
|
13
|
+
// src/messages.ts
|
|
14
|
+
var SolanaErrorMessages = {
|
|
15
|
+
[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`",
|
|
16
|
+
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses",
|
|
17
|
+
[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."
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/message-formatter.ts
|
|
21
|
+
function getHumanReadableErrorMessage(code, context = {}) {
|
|
22
|
+
const messageFormatString = SolanaErrorMessages[code];
|
|
23
|
+
const message = messageFormatString.replace(
|
|
24
|
+
/(?<!\\)\$(\w+)/g,
|
|
25
|
+
(substring, variableName) => variableName in context ? `${context[variableName]}` : substring
|
|
26
|
+
);
|
|
27
|
+
return message;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/cli.ts
|
|
31
|
+
var program = new Command();
|
|
32
|
+
program.name("@solana/errors").description("Decode Solana JavaScript errors thrown in production").version(version);
|
|
33
|
+
program.command("decode").description("Decode a `SolanaErrorCode` to a human-readable message").argument("<code>", "numeric error code to decode", (rawCode) => {
|
|
34
|
+
const code = parseInt(rawCode, 10);
|
|
35
|
+
if (isNaN(code) || `${code}` !== rawCode) {
|
|
36
|
+
throw new InvalidArgumentError("It must be an integer");
|
|
37
|
+
}
|
|
38
|
+
if (!(code in SolanaErrorMessages)) {
|
|
39
|
+
throw new InvalidArgumentError("There exists no error with that code");
|
|
40
|
+
}
|
|
41
|
+
return code;
|
|
42
|
+
}).argument(
|
|
43
|
+
"[encodedContext]",
|
|
44
|
+
"encoded context to interpolate into the error message",
|
|
45
|
+
(encodedContext) => Object.fromEntries(new URLSearchParams(encodedContext).entries())
|
|
46
|
+
).action((code, context) => {
|
|
47
|
+
const message = getHumanReadableErrorMessage(code, context);
|
|
48
|
+
console.log(`
|
|
49
|
+
${chalk.bold(
|
|
50
|
+
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)("]")
|
|
51
|
+
) + chalk.rgb(19, 241, 149)(" Solana error code #" + code)}
|
|
52
|
+
- ${message}`);
|
|
53
|
+
if (context) {
|
|
54
|
+
console.log(`
|
|
55
|
+
${chalk.yellowBright(chalk.bold("[Context]"))}
|
|
56
|
+
${JSON.stringify(context, null, 4).split("\n").join("\n ")}`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
function run(argv) {
|
|
60
|
+
program.parse(argv);
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
run
|
|
64
|
+
};
|
package/dist/index.browser.cjs
CHANGED
|
@@ -6,9 +6,11 @@ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(
|
|
|
6
6
|
// src/codes.ts
|
|
7
7
|
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
8
8
|
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
9
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
9
10
|
|
|
10
11
|
// src/messages.ts
|
|
11
12
|
var SolanaErrorMessages = {
|
|
13
|
+
[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`",
|
|
12
14
|
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses",
|
|
13
15
|
[SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]: "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
14
16
|
};
|
|
@@ -90,6 +92,7 @@ var SolanaError = class extends Error {
|
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
94
|
|
|
95
|
+
exports.SOLANA_ERROR__RPC_INTEGER_OVERFLOW = SOLANA_ERROR__RPC_INTEGER_OVERFLOW;
|
|
93
96
|
exports.SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES;
|
|
94
97
|
exports.SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE;
|
|
95
98
|
exports.SolanaError = SolanaError;
|
|
@@ -1 +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;;;
|
|
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;;;ACI3C,IAAM,sBAIR;AAAA,EACD,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;ACxBA,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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,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;\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","import {\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__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"]}
|
package/dist/index.browser.js
CHANGED
|
@@ -4,9 +4,11 @@ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(
|
|
|
4
4
|
// src/codes.ts
|
|
5
5
|
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
6
6
|
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
7
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
7
8
|
|
|
8
9
|
// src/messages.ts
|
|
9
10
|
var SolanaErrorMessages = {
|
|
11
|
+
[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`",
|
|
10
12
|
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses",
|
|
11
13
|
[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."
|
|
12
14
|
};
|
|
@@ -88,6 +90,6 @@ var SolanaError = class extends Error {
|
|
|
88
90
|
}
|
|
89
91
|
};
|
|
90
92
|
|
|
91
|
-
export { SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
93
|
+
export { SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
92
94
|
//# sourceMappingURL=out.js.map
|
|
93
95
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +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;;;
|
|
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;;;ACI3C,IAAM,sBAIR;AAAA,EACD,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;ACxBA,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;\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","import {\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__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"]}
|
package/dist/index.native.js
CHANGED
|
@@ -4,9 +4,11 @@ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(
|
|
|
4
4
|
// src/codes.ts
|
|
5
5
|
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
6
6
|
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
7
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
7
8
|
|
|
8
9
|
// src/messages.ts
|
|
9
10
|
var SolanaErrorMessages = {
|
|
11
|
+
[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`",
|
|
10
12
|
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses",
|
|
11
13
|
[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."
|
|
12
14
|
};
|
|
@@ -88,6 +90,6 @@ var SolanaError = class extends Error {
|
|
|
88
90
|
}
|
|
89
91
|
};
|
|
90
92
|
|
|
91
|
-
export { SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
93
|
+
export { SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
92
94
|
//# sourceMappingURL=out.js.map
|
|
93
95
|
//# sourceMappingURL=index.native.js.map
|
package/dist/index.native.js.map
CHANGED
|
@@ -1 +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;;;
|
|
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;;;ACI3C,IAAM,sBAIR;AAAA,EACD,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;ACxBA,SAAS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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;\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","import {\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__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"]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -6,9 +6,11 @@ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(
|
|
|
6
6
|
// src/codes.ts
|
|
7
7
|
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
8
8
|
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
9
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
9
10
|
|
|
10
11
|
// src/messages.ts
|
|
11
12
|
var SolanaErrorMessages = {
|
|
13
|
+
[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`",
|
|
12
14
|
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses",
|
|
13
15
|
[SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE]: "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
14
16
|
};
|
|
@@ -90,6 +92,7 @@ var SolanaError = class extends Error {
|
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
94
|
|
|
95
|
+
exports.SOLANA_ERROR__RPC_INTEGER_OVERFLOW = SOLANA_ERROR__RPC_INTEGER_OVERFLOW;
|
|
93
96
|
exports.SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES;
|
|
94
97
|
exports.SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE;
|
|
95
98
|
exports.SolanaError = SolanaError;
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +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;;;
|
|
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;;;ACI3C,IAAM,sBAIR;AAAA,EACD,CAAC,kCAAkC,GAC/B;AAAA,EAGJ,CAAC,4CAA4C,GAAG;AAAA,EAChD,CAAC,kDAAkD,GAC/C;AAER;;;ACxBA,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,IAC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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;\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","import {\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__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"]}
|
package/dist/index.node.js
CHANGED
|
@@ -4,9 +4,11 @@ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(
|
|
|
4
4
|
// src/codes.ts
|
|
5
5
|
var SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES = 1;
|
|
6
6
|
var SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE = 2;
|
|
7
|
+
var SOLANA_ERROR__RPC_INTEGER_OVERFLOW = 3;
|
|
7
8
|
|
|
8
9
|
// src/messages.ts
|
|
9
10
|
var SolanaErrorMessages = {
|
|
11
|
+
[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`",
|
|
10
12
|
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: "Transaction is missing signatures for addresses: $addresses",
|
|
11
13
|
[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."
|
|
12
14
|
};
|
|
@@ -88,6 +90,6 @@ var SolanaError = class extends Error {
|
|
|
88
90
|
}
|
|
89
91
|
};
|
|
90
92
|
|
|
91
|
-
export { SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
93
|
+
export { SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SolanaError, isSolanaError };
|
|
92
94
|
//# sourceMappingURL=out.js.map
|
|
93
95
|
//# sourceMappingURL=index.node.js.map
|
package/dist/index.node.js.map
CHANGED
|
@@ -1 +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;;;
|
|
1
|
+
{"version":3,"sources":["../../build-scripts/env-shim.ts","../src/codes.ts","../src/messages.ts","../src/message-form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S,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;\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","import {\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__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"]}
|
package/dist/types/codes.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES: 1;
|
|
10
10
|
export declare const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE: 2;
|
|
11
|
+
export declare const SOLANA_ERROR__RPC_INTEGER_OVERFLOW: 3;
|
|
11
12
|
/**
|
|
12
13
|
* A union of every Solana error code
|
|
13
14
|
*
|
|
@@ -23,5 +24,5 @@ export declare const SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE: 2;
|
|
|
23
24
|
* actually used. Unfortunately exporting ambient (const) enums from a library like `@solana/errors`
|
|
24
25
|
* is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850
|
|
25
26
|
*/
|
|
26
|
-
export type SolanaErrorCode = typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE;
|
|
27
|
+
export type SolanaErrorCode = typeof SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES | typeof SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE | typeof SOLANA_ERROR__RPC_INTEGER_OVERFLOW;
|
|
27
28
|
//# sourceMappingURL=codes.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAE7D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GACrB,OAAO,4CAA4C,GACnD,OAAO,kDAAkD,GACzD,OAAO,kCAAkC,CAAC"}
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SolanaErrorCode } from './codes.js';
|
|
1
|
+
import { SOLANA_ERROR__RPC_INTEGER_OVERFLOW, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SolanaErrorCode } from './codes.js';
|
|
2
2
|
export type DefaultUnspecifiedErrorContextToUndefined<T> = {
|
|
3
3
|
[P in SolanaErrorCode]: P extends keyof T ? T[P] : undefined;
|
|
4
4
|
};
|
|
@@ -13,5 +13,13 @@ export type SolanaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
|
|
|
13
13
|
[SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES]: {
|
|
14
14
|
addresses: string[];
|
|
15
15
|
};
|
|
16
|
+
[SOLANA_ERROR__RPC_INTEGER_OVERFLOW]: {
|
|
17
|
+
argumentLabel: string;
|
|
18
|
+
keyPath: readonly (string | number | symbol)[];
|
|
19
|
+
methodName: string;
|
|
20
|
+
optionalPathLabel: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
value: bigint;
|
|
23
|
+
};
|
|
16
24
|
}>;
|
|
17
25
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,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,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;CACL,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,eAAe,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC;KAGtC,CAAC,IAAI,eAAe,GAAG,MAAM;CACjC,CASA,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
},
|
|
2
|
+
"name": "@solana/errors",
|
|
3
|
+
"version": "2.0.0-experimental.dd2096e",
|
|
4
|
+
"description": "Throw, identify, and decode Solana JavaScript errors",
|
|
5
|
+
"exports": {
|
|
17
6
|
"browser": {
|
|
18
|
-
|
|
19
|
-
|
|
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"
|
|
20
13
|
},
|
|
21
|
-
"main": "./dist/index.node.cjs",
|
|
22
|
-
"module": "./dist/index.node.js",
|
|
23
14
|
"react-native": "./dist/index.native.js",
|
|
24
|
-
"types": "./dist/types/index.d.ts"
|
|
25
|
-
|
|
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
|
+
"commander": "^11.1.0",
|
|
54
|
+
"chalk": "^5.3.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@solana/eslint-config-solana": "^1.0.2",
|
|
58
|
+
"@swc/jest": "^0.2.29",
|
|
59
|
+
"@types/jest": "^29.5.11",
|
|
60
|
+
"@types/node": "18.11.19",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
62
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
63
|
+
"agadoo": "^3.0.0",
|
|
64
|
+
"eslint": "^8.45.0",
|
|
65
|
+
"eslint-plugin-jest": "^27.4.2",
|
|
66
|
+
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
67
|
+
"jest": "^29.7.0",
|
|
68
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
69
|
+
"jest-runner-eslint": "^2.1.2",
|
|
70
|
+
"jest-runner-prettier": "^1.0.0",
|
|
71
|
+
"prettier": "^3.1",
|
|
72
|
+
"tsup": "^8.0.1",
|
|
73
|
+
"typescript": "^5.2.2",
|
|
74
|
+
"version-from-git": "^1.1.1",
|
|
75
|
+
"build-scripts": "0.0.0",
|
|
76
|
+
"test-config": "0.0.0",
|
|
77
|
+
"tsconfig": "0.0.0",
|
|
78
|
+
"@solana/addresses": "2.0.0-experimental.dd2096e"
|
|
79
|
+
},
|
|
80
|
+
"bundlewatch": {
|
|
81
|
+
"defaultCompression": "gzip",
|
|
26
82
|
"files": [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"test:typecheck": "tsc --noEmit",
|
|
49
|
-
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
50
|
-
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
51
|
-
},
|
|
52
|
-
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
|
53
|
-
"license": "MIT",
|
|
54
|
-
"repository": {
|
|
55
|
-
"type": "git",
|
|
56
|
-
"url": "https://github.com/solana-labs/solana-web3.js"
|
|
57
|
-
},
|
|
58
|
-
"bugs": {
|
|
59
|
-
"url": "http://github.com/solana-labs/solana-web3.js/issues"
|
|
60
|
-
},
|
|
61
|
-
"browserslist": [
|
|
62
|
-
"supports bigint and not dead",
|
|
63
|
-
"maintained node versions"
|
|
64
|
-
],
|
|
65
|
-
"engine": {
|
|
66
|
-
"node": ">=17.4"
|
|
67
|
-
},
|
|
68
|
-
"devDependencies": {
|
|
69
|
-
"@solana/addresses": "2.0.0-experimental.b93299a",
|
|
70
|
-
"@solana/eslint-config-solana": "^1.0.2",
|
|
71
|
-
"@swc/jest": "^0.2.29",
|
|
72
|
-
"@types/jest": "^29.5.11",
|
|
73
|
-
"@types/node": "18.11.19",
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
75
|
-
"@typescript-eslint/parser": "^6.3.0",
|
|
76
|
-
"agadoo": "^3.0.0",
|
|
77
|
-
"build-scripts": "0.0.0",
|
|
78
|
-
"chalk": "^5.3.0",
|
|
79
|
-
"commander": "^11.1.0",
|
|
80
|
-
"eslint": "^8.45.0",
|
|
81
|
-
"eslint-plugin-jest": "^27.4.2",
|
|
82
|
-
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
83
|
-
"jest": "^29.7.0",
|
|
84
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
85
|
-
"jest-runner-eslint": "^2.1.2",
|
|
86
|
-
"jest-runner-prettier": "^1.0.0",
|
|
87
|
-
"prettier": "^3.1",
|
|
88
|
-
"test-config": "0.0.0",
|
|
89
|
-
"tsconfig": "0.0.0",
|
|
90
|
-
"tsup": "^8.0.1",
|
|
91
|
-
"tsx": "^4.7.0",
|
|
92
|
-
"typescript": "^5.2.2",
|
|
93
|
-
"version-from-git": "^1.1.1"
|
|
94
|
-
},
|
|
95
|
-
"bundlewatch": {
|
|
96
|
-
"defaultCompression": "gzip",
|
|
97
|
-
"files": [
|
|
98
|
-
{
|
|
99
|
-
"path": "./dist/index*.js"
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
}
|
|
83
|
+
{
|
|
84
|
+
"path": "./dist/index*.js"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts && tsup src/cli.ts --format esm",
|
|
90
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
|
|
91
|
+
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
92
|
+
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
93
|
+
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
94
|
+
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
95
|
+
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
96
|
+
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
97
|
+
"test:treeshakability:native": "agadoo dist/index.native.js",
|
|
98
|
+
"test:treeshakability:node": "agadoo dist/index.node.js",
|
|
99
|
+
"test:typecheck": "tsc --noEmit",
|
|
100
|
+
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
101
|
+
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
102
|
+
}
|
|
103
|
+
}
|
package/bin/cli.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S tsx
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { Command, InvalidArgumentError } from 'commander';
|
|
5
|
-
|
|
6
|
-
import { version } from '../package.json';
|
|
7
|
-
import { SolanaErrorCode } from '../src/codes';
|
|
8
|
-
import { getHumanReadableErrorMessage } from '../src/message-formatter';
|
|
9
|
-
import { SolanaErrorMessages } from '../src/messages';
|
|
10
|
-
|
|
11
|
-
const program = new Command();
|
|
12
|
-
|
|
13
|
-
program.name('@solana/errors').description('Decode Solana JavaScript errors thrown in production').version(version);
|
|
14
|
-
|
|
15
|
-
program
|
|
16
|
-
.command('decode')
|
|
17
|
-
.description('Decode a `SolanaErrorCode` to a human-readable message')
|
|
18
|
-
.argument('<code>', 'numeric error code to decode', rawCode => {
|
|
19
|
-
const code = parseInt(rawCode, 10);
|
|
20
|
-
if (isNaN(code) || `${code}` !== rawCode) {
|
|
21
|
-
throw new InvalidArgumentError('It must be an integer');
|
|
22
|
-
}
|
|
23
|
-
if (!(code in SolanaErrorMessages)) {
|
|
24
|
-
throw new InvalidArgumentError('There exists no error with that code');
|
|
25
|
-
}
|
|
26
|
-
return code;
|
|
27
|
-
})
|
|
28
|
-
.argument('[encodedContext]', 'encoded context to interpolate into the error message', encodedContext =>
|
|
29
|
-
Object.fromEntries(new URLSearchParams(encodedContext).entries()),
|
|
30
|
-
)
|
|
31
|
-
.action((code: number, context) => {
|
|
32
|
-
const message = getHumanReadableErrorMessage(code as SolanaErrorCode, context);
|
|
33
|
-
console.log(`
|
|
34
|
-
${
|
|
35
|
-
chalk.bold(
|
|
36
|
-
chalk.rgb(154, 71, 255)('[') +
|
|
37
|
-
chalk.rgb(144, 108, 244)('D') +
|
|
38
|
-
chalk.rgb(134, 135, 233)('e') +
|
|
39
|
-
chalk.rgb(122, 158, 221)('c') +
|
|
40
|
-
chalk.rgb(110, 178, 209)('o') +
|
|
41
|
-
chalk.rgb(95, 195, 196)('d') +
|
|
42
|
-
chalk.rgb(79, 212, 181)('e') +
|
|
43
|
-
chalk.rgb(57, 227, 166)('d') +
|
|
44
|
-
chalk.rgb(19, 241, 149)(']'),
|
|
45
|
-
) + chalk.rgb(19, 241, 149)(' Solana error code #' + code)
|
|
46
|
-
}
|
|
47
|
-
- ${message}`);
|
|
48
|
-
if (context) {
|
|
49
|
-
console.log(`
|
|
50
|
-
${chalk.yellowBright(chalk.bold('[Context]'))}
|
|
51
|
-
${JSON.stringify(context, null, 4).split('\n').join('\n ')}`);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
program.parse();
|