@layerzerolabs/common-error-utils 0.2.19 → 0.2.21
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/.turbo/turbo-build.log +16 -16
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +4 -4
- package/dist/{W7EWJMEA.js → HSJL4TXR.js} +6 -3
- package/dist/HSJL4TXR.js.map +1 -0
- package/dist/{YBBPQS6P.cjs → MXJDS64O.cjs} +6 -2
- package/dist/MXJDS64O.cjs.map +1 -0
- package/dist/errors.cjs +15 -11
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.cjs +15 -11
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/errors.ts +8 -0
- package/dist/W7EWJMEA.js.map +0 -1
- package/dist/YBBPQS6P.cjs.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -11,29 +11,29 @@
|
|
|
11
11
|
[34mCLI[39m Cleaning output folder
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
13
|
[34mESM[39m Build start
|
|
14
|
-
[32mCJS[39m [1mdist/errors.cjs [22m[32m1.
|
|
15
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m1.
|
|
16
|
-
[32mCJS[39m [1mdist/
|
|
17
|
-
[32mCJS[39m [1mdist/YBBPQS6P.cjs [22m[32m4.86 KB[39m
|
|
18
|
-
[32mCJS[39m [1mdist/4FQD32GO.cjs [22m[32m1.65 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/errors.cjs [22m[32m1.63 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m1.81 KB[39m
|
|
16
|
+
[32mCJS[39m [1mdist/MXJDS64O.cjs [22m[32m5.06 KB[39m
|
|
19
17
|
[32mCJS[39m [1mdist/YJF4D23A.cjs [22m[32m245.00 B[39m
|
|
18
|
+
[32mCJS[39m [1mdist/4FQD32GO.cjs [22m[32m1.65 KB[39m
|
|
19
|
+
[32mCJS[39m [1mdist/retry.cjs [22m[32m304.00 B[39m
|
|
20
20
|
[32mCJS[39m [1mdist/errors.cjs.map [22m[32m71.00 B[39m
|
|
21
21
|
[32mCJS[39m [1mdist/index.cjs.map [22m[32m70.00 B[39m
|
|
22
|
+
[32mCJS[39m [1mdist/MXJDS64O.cjs.map [22m[32m10.18 KB[39m
|
|
23
|
+
[32mCJS[39m [1mdist/YJF4D23A.cjs.map [22m[32m73.00 B[39m
|
|
22
24
|
[32mCJS[39m [1mdist/retry.cjs.map [22m[32m70.00 B[39m
|
|
23
|
-
[32mCJS[39m [1mdist/YBBPQS6P.cjs.map [22m[32m9.79 KB[39m
|
|
24
25
|
[32mCJS[39m [1mdist/4FQD32GO.cjs.map [22m[32m5.24 KB[39m
|
|
25
|
-
[32mCJS[39m
|
|
26
|
-
[
|
|
27
|
-
[32mESM[39m [1mdist/
|
|
28
|
-
[32mESM[39m [1mdist/W7EWJMEA.js [22m[32m4.46 KB[39m
|
|
26
|
+
[32mCJS[39m ⚡️ Build success in 144ms
|
|
27
|
+
[32mESM[39m [1mdist/errors.js [22m[32m315.00 B[39m
|
|
28
|
+
[32mESM[39m [1mdist/index.js [22m[32m365.00 B[39m
|
|
29
29
|
[32mESM[39m [1mdist/retry.js [22m[32m143.00 B[39m
|
|
30
|
-
[32mESM[39m [1mdist/
|
|
30
|
+
[32mESM[39m [1mdist/HSJL4TXR.js [22m[32m4.62 KB[39m
|
|
31
31
|
[32mESM[39m [1mdist/VUOMXK5T.js [22m[32m222.00 B[39m
|
|
32
|
+
[32mESM[39m [1mdist/ZLKJGRU2.js [22m[32m1.37 KB[39m
|
|
32
33
|
[32mESM[39m [1mdist/errors.js.map [22m[32m70.00 B[39m
|
|
33
|
-
[32mESM[39m [1mdist/
|
|
34
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m69.00 B[39m
|
|
34
35
|
[32mESM[39m [1mdist/retry.js.map [22m[32m69.00 B[39m
|
|
35
|
-
[32mESM[39m [1mdist/
|
|
36
|
+
[32mESM[39m [1mdist/HSJL4TXR.js.map [22m[32m10.17 KB[39m
|
|
36
37
|
[32mESM[39m [1mdist/VUOMXK5T.js.map [22m[32m72.00 B[39m
|
|
37
|
-
[32mESM[39m [1mdist/
|
|
38
|
-
[32mESM[39m
|
|
39
|
-
[32mESM[39m ⚡️ Build success in 294ms
|
|
38
|
+
[32mESM[39m [1mdist/ZLKJGRU2.js.map [22m[32m5.22 KB[39m
|
|
39
|
+
[32mESM[39m ⚡️ Build success in 144ms
|
package/.turbo/turbo-lint.log
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
> @layerzerolabs/common-error-utils@0.0.0 lint /home/runner/work/monorepo-internal/monorepo-internal/packages/common/common-error-utils
|
|
3
3
|
> eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)
|
|
4
4
|
|
|
5
|
-
(node:
|
|
5
|
+
(node:47525) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1769560295397 is not specified and it doesn't parse as CommonJS.
|
|
6
6
|
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
|
|
7
7
|
To eliminate this warning, add "type": "module" to /home/runner/work/monorepo-internal/monorepo-internal/package.json.
|
|
8
8
|
(Use `node --trace-warnings ...` to show where the warning was created)
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -22,12 +22,12 @@ Breaking changes might not follow SemVer, please pin Vitest's version when using
|
|
|
22
22
|
at runSuite (file:///home/runner/work/monorepo-internal/monorepo-internal/node_modules/[4m.pnpm[24m/@vitest+runner@3.2.4/node_modules/[4m@vitest/runner[24m/dist/chunk-hooks.js:1729:8)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
[32m✓[39m tests/error.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m
|
|
26
|
-
[32m✓[39m tests/retry.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m
|
|
25
|
+
[32m✓[39m tests/error.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 11[2mms[22m[39m
|
|
26
|
+
[32m✓[39m tests/retry.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 68[2mms[22m[39m
|
|
27
27
|
|
|
28
28
|
[2m Test Files [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
|
29
29
|
[2m Tests [22m [1m[32m9 passed[39m[22m[90m (9)[39m
|
|
30
30
|
[2mType Errors [22m [2mno errors[22m
|
|
31
|
-
[2m Start at [22m 00:
|
|
32
|
-
[2m Duration [22m
|
|
31
|
+
[2m Start at [22m 00:33:40
|
|
32
|
+
[2m Duration [22m 476ms[2m (transform 112ms, setup 0ms, collect 170ms, tests 78ms, environment 0ms, prepare 208ms)[22m
|
|
33
33
|
|
|
@@ -156,7 +156,10 @@ var MultiError = class extends Error {
|
|
|
156
156
|
var throwError = /* @__PURE__ */ __name((message, error) => {
|
|
157
157
|
throw error?.(message) ?? new Error(message);
|
|
158
158
|
}, "throwError");
|
|
159
|
+
var assertUnreachable = /* @__PURE__ */ __name((value) => {
|
|
160
|
+
throw new NonRetryableError(`Unreachable value: ${value}`);
|
|
161
|
+
}, "assertUnreachable");
|
|
159
162
|
|
|
160
|
-
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, convertErrorToObject, normalizeError, throwError };
|
|
161
|
-
//# sourceMappingURL=
|
|
162
|
-
//# sourceMappingURL=
|
|
163
|
+
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError };
|
|
164
|
+
//# sourceMappingURL=HSJL4TXR.js.map
|
|
165
|
+
//# sourceMappingURL=HSJL4TXR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":["extractMessageFromJsonRpcError","err","body","message","parsedBody","JSON","parse","error","convertErrorToObject","stringify","Object","getOwnPropertyNames","normalizeError","name","stack","reason","code","event","SerializableError","Error","details","cause","options","inStackOf","includes","undefined","wrap","args","wrappedError","String","NonRetryableError","NotFoundError","ProviderError","providerUri","parseHost","url","URL","host","NonEmittableError","QuorumNotAchievedYet","MultiError","errs","map","join","throwError","assertUnreachable","value"],"mappings":";;;AAAA,IAAMA,8BAAAA,2BAAkCC,GAAAA,KAAAA;AACpC,EAAA,IAAI;AACA,IAAA,IAAI,OAAOA,GAAAA,CAAIC,IAAAA,KAAS,QAAA,IAAYD,GAAAA,CAAIC,KAAKC,OAAAA,EAAS;AAClD,MAAA,OAAOF,IAAIC,IAAAA,CAAKC,OAAAA;AACpB,IAAA;AACA,IAAA,MAAMC,UAAAA,GAAaC,IAAAA,CAAKC,KAAAA,CAAML,GAAAA,CAAIC,IAAI,CAAA;AACtC,IAAA,OAAOE,YAAYG,KAAAA,EAAOJ,OAAAA;EAC9B,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,SAAA;AACX,EAAA;AACJ,CAAA,EAVuC,gCAAA,CAAA;AAYhC,SAASK,qBAAqBP,GAAAA,EAAQ;AACzC,EAAA,OAAOI,IAAAA,CAAKC,MAAMD,IAAAA,CAAKI,SAAAA,CAAUR,KAAKS,MAAAA,CAAOC,mBAAAA,CAAoBV,GAAAA,CAAAA,CAAAA,CAAAA;AACrE;AAFgBO,MAAAA,CAAAA,oBAAAA,EAAAA,sBAAAA,CAAAA;AAIT,SAASI,eAAeX,GAAAA,EAAQ;AACnC,EAAA,MAAMM,KAAAA,GAAQC,qBAAqBP,GAAAA,CAAAA;AACnC,EAAA,OAAO;;AAEH,IAAA,GAAIM,MAAMM,IAAAA,GAAO;AAAEA,MAAAA,IAAAA,EAAMN,KAAAA,CAAMM;AAAK,KAAA,GAAI,EAAC;AACzC,IAAA,GAAIN,MAAMJ,OAAAA,GAAU;AAAEA,MAAAA,OAAAA,EAASI,KAAAA,CAAMJ;AAAQ,KAAA,GAA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A,KAAAA,GAAQJ,OAAAA,CAAAA,IAAY,IAAIgB,MAAMhB,OAAAA,CAAAA;AACxC,CAAA,EAL0B,YAAA;AAWnB,IAAM0C,iBAAAA,2BAAqBC,KAAAA,KAAAA;AAC9B,EAAA,MAAM,IAAIhB,iBAAAA,CAAkB,CAAA,mBAAA,EAAsBgB,KAAAA,CAAAA,CAAO,CAAA;AAC7D,CAAA,EAFiC,mBAAA","file":"HSJL4TXR.js","sourcesContent":["const extractMessageFromJsonRpcError = (err: any): string => {\n try {\n if (typeof err.body === 'object' && err.body.message) {\n return err.body.message;\n }\n const parsedBody = JSON.parse(err.body);\n return parsedBody?.error?.message;\n } catch {\n return 'unknown';\n }\n};\n\nexport function convertErrorToObject(err: any): any {\n return JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err)));\n}\n\nexport function normalizeError(err: any) {\n const error = convertErrorToObject(err);\n return {\n // Normal Error properties\n ...(error.name ? { name: error.name } : {}),\n ...(error.message ? { message: error.message } : {}),\n ...(error.stack ? { stack: error.stack } : {}),\n // Rpc properties\n ...(error.reason ? { reason: error.reason } : {}),\n ...(error.code ? { code: error.code } : {}),\n ...(error.event ? { event: error.event } : {}),\n ...(error.body ? { body: extractMessageFromJsonRpcError(error) } : {}),\n };\n}\n\n// Removes the last argument if it is an ErrorOptions\ntype RemoveErrorOptions<T extends any[]> = T extends [...infer U, ErrorOptions?] ? U : never;\n\n/**\n * Base class for all serializable errors.\n * This class is designed to be extended by other error classes.\n * It provides a way to wrap errors and a way to check if an error is in the stack of a specific error class.\n * All errors that extend this class *must* have error options as the last argument in their constructor.\n */\nexport abstract class SerializableError extends Error {\n details: string[];\n /*\n * The instance of the error that was wrapped, if any.\n * Creates a linked list of error objects.\n * Only exists if the error hasn't been serialized and deserialized.\n */\n cause: unknown;\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n // for some reason, we need to set the cause directly on the instance, even after calling super\n this.cause = options?.cause;\n this.name = this.constructor.name;\n this.details = [this.constructor.name, 'SerializableError'];\n }\n\n /*\n * Checks if the error is an instance of the current class or a subclass. Returns the error if it is.\n * We can't type the error as more than SerializableError because it could have been serialized and deserialized,\n * which could make it lose extra fields.\n */\n static inStackOf<T extends abstract new (...args: any) => any>(\n this: T,\n error: any,\n ): SerializableError | undefined {\n if (error?.details?.includes(this.name)) {\n return error as SerializableError;\n } else if (error?.cause?.details?.includes(this.name)) {\n return error.cause as SerializableError;\n }\n return undefined;\n }\n\n // We could limit this to only wrap serializable errors, but that could limit the flexibility of the error system.\n static wrap<T extends new (...args: any) => SerializableError>(\n this: T,\n error: any,\n // Remove the optional error arguments\n ...args: RemoveErrorOptions<ConstructorParameters<T>>\n ): InstanceType<T> {\n const wrappedError = new this(...args, { cause: error });\n\n wrappedError.details = error?.details\n ? [wrappedError.name, ...error.details]\n : [wrappedError.name, 'SerializableError', error?.name ?? 'UnknownError'];\n\n wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;\n\n return wrappedError as InstanceType<T>;\n }\n}\n\nexport class NonRetryableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\nexport class NotFoundError extends SerializableError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message ? `Not found: ${message}` : 'Not found', options);\n }\n}\n\n// TODO: extend this for chain specific providers\nexport class ProviderError extends SerializableError {\n constructor(providerUri: string, options?: ErrorOptions) {\n super(`Provider error at host '${ProviderError.parseHost(providerUri)}'`, options);\n }\n\n private static parseHost(providerUri: string): string {\n try {\n const url = new URL(providerUri);\n return url.host;\n } catch {\n return 'UNKNOWN_HOST';\n }\n }\n}\n\nexport class NonEmittableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'NonEmittableError';\n }\n}\n\nexport class QuorumNotAchievedYet extends SerializableError {\n constructor(options?: ErrorOptions) {\n super('The quorum was not achieved yet', options);\n }\n}\n\nexport class MultiError extends Error {\n constructor(public readonly errs: any[]) {\n super(errs.map((err) => err.message).join(', '));\n }\n}\n\nexport const throwError = <Err extends Error>(\n message: string,\n error?: (message: string) => Err,\n): never => {\n throw error?.(message) ?? new Error(message);\n};\n\n/**\n * Assert that a value is never.\n * Most useful for enforcing exhaustive switch statements.\n */\nexport const assertUnreachable = (value: never): never => {\n throw new NonRetryableError(`Unreachable value: ${value}`);\n};\n"]}
|
|
@@ -158,6 +158,9 @@ var MultiError = class extends Error {
|
|
|
158
158
|
var throwError = /* @__PURE__ */ YJF4D23A_cjs.__name((message, error) => {
|
|
159
159
|
throw error?.(message) ?? new Error(message);
|
|
160
160
|
}, "throwError");
|
|
161
|
+
var assertUnreachable = /* @__PURE__ */ YJF4D23A_cjs.__name((value) => {
|
|
162
|
+
throw new NonRetryableError(`Unreachable value: ${value}`);
|
|
163
|
+
}, "assertUnreachable");
|
|
161
164
|
|
|
162
165
|
exports.MultiError = MultiError;
|
|
163
166
|
exports.NonEmittableError = NonEmittableError;
|
|
@@ -166,8 +169,9 @@ exports.NotFoundError = NotFoundError;
|
|
|
166
169
|
exports.ProviderError = ProviderError;
|
|
167
170
|
exports.QuorumNotAchievedYet = QuorumNotAchievedYet;
|
|
168
171
|
exports.SerializableError = SerializableError;
|
|
172
|
+
exports.assertUnreachable = assertUnreachable;
|
|
169
173
|
exports.convertErrorToObject = convertErrorToObject;
|
|
170
174
|
exports.normalizeError = normalizeError;
|
|
171
175
|
exports.throwError = throwError;
|
|
172
|
-
//# sourceMappingURL=
|
|
173
|
-
//# sourceMappingURL=
|
|
176
|
+
//# sourceMappingURL=MXJDS64O.cjs.map
|
|
177
|
+
//# sourceMappingURL=MXJDS64O.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":["extractMessageFromJsonRpcError","err","body","message","parsedBody","JSON","parse","error","convertErrorToObject","stringify","Object","getOwnPropertyNames","normalizeError","name","stack","reason","code","event","SerializableError","Error","details","cause","options","inStackOf","includes","undefined","wrap","args","wrappedError","String","NonRetryableError","NotFoundError","ProviderError","providerUri","parseHost","url","URL","host","NonEmittableError","QuorumNotAchievedYet","MultiError","errs","map","join","throwError","__name","assertUnreachable","value"],"mappings":";;;;;AAAA,IAAMA,8BAAAA,wCAAkCC,GAAAA,KAAAA;AACpC,EAAA,IAAI;AACA,IAAA,IAAI,OAAOA,GAAAA,CAAIC,IAAAA,KAAS,QAAA,IAAYD,GAAAA,CAAIC,KAAKC,OAAAA,EAAS;AAClD,MAAA,OAAOF,IAAIC,IAAAA,CAAKC,OAAAA;AACpB,IAAA;AACA,IAAA,MAAMC,UAAAA,GAAaC,IAAAA,CAAKC,KAAAA,CAAML,GAAAA,CAAIC,IAAI,CAAA;AACtC,IAAA,OAAOE,YAAYG,KAAAA,EAAOJ,OAAAA;EAC9B,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,SAAA;AACX,EAAA;AACJ,CAAA,EAVuC,gCAAA,CAAA;AAYhC,SAASK,qBAAqBP,GAAAA,EAAQ;AACzC,EAAA,OAAOI,IAAAA,CAAKC,MAAMD,IAAAA,CAAKI,SAAAA,CAAUR,KAAKS,MAAAA,CAAOC,mBAAAA,CAAoBV,GAAAA,CAAAA,CAAAA,CAAAA;AACrE;AAFgBO,mBAAAA,CAAAA,oBAAAA,EAAAA,sBAAAA,CAAAA;AAIT,SAASI,eAAeX,GAAAA,EAAQ;AACnC,EAAA,MAAMM,KAAAA,GAAQC,qBAAqBP,GAAAA,CAAAA;AACnC,EAAA,OAAO;;AAEH,IAAA,GAAIM,MAAMM,IAAAA,GAAO;AAAEA,MAAAA,IAAAA,EAAMN,KAAAA,CAAMM;AAAK,KAAA,GAAI,EAAC;AACzC,IAAA,GAAIN,MAAMJ,OAAAA,GAAU;AAAEA,MAAAA,OAAAA,EAASI,KAAAA,CAAMJ;AAAQ,KAAA,GAAI,EAAC;AAClD,IAAA,GAAII,MAAMO,KAAAA,GAAQ;AAAEA,MAAAA,KAAAA,EAAOP,KAAAA,CAAMO;AAAM,KAAA,GAAI,EAAC;;AAE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A,wCAAqBC,KAAAA,KAAAA;AAC9B,EAAA,MAAM,IAAIjB,iBAAAA,CAAkB,CAAA,mBAAA,EAAsBiB,KAAAA,CAAAA,CAAO,CAAA;AAC7D,CAAA,EAFiC,mBAAA","file":"MXJDS64O.cjs","sourcesContent":["const extractMessageFromJsonRpcError = (err: any): string => {\n try {\n if (typeof err.body === 'object' && err.body.message) {\n return err.body.message;\n }\n const parsedBody = JSON.parse(err.body);\n return parsedBody?.error?.message;\n } catch {\n return 'unknown';\n }\n};\n\nexport function convertErrorToObject(err: any): any {\n return JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err)));\n}\n\nexport function normalizeError(err: any) {\n const error = convertErrorToObject(err);\n return {\n // Normal Error properties\n ...(error.name ? { name: error.name } : {}),\n ...(error.message ? { message: error.message } : {}),\n ...(error.stack ? { stack: error.stack } : {}),\n // Rpc properties\n ...(error.reason ? { reason: error.reason } : {}),\n ...(error.code ? { code: error.code } : {}),\n ...(error.event ? { event: error.event } : {}),\n ...(error.body ? { body: extractMessageFromJsonRpcError(error) } : {}),\n };\n}\n\n// Removes the last argument if it is an ErrorOptions\ntype RemoveErrorOptions<T extends any[]> = T extends [...infer U, ErrorOptions?] ? U : never;\n\n/**\n * Base class for all serializable errors.\n * This class is designed to be extended by other error classes.\n * It provides a way to wrap errors and a way to check if an error is in the stack of a specific error class.\n * All errors that extend this class *must* have error options as the last argument in their constructor.\n */\nexport abstract class SerializableError extends Error {\n details: string[];\n /*\n * The instance of the error that was wrapped, if any.\n * Creates a linked list of error objects.\n * Only exists if the error hasn't been serialized and deserialized.\n */\n cause: unknown;\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n // for some reason, we need to set the cause directly on the instance, even after calling super\n this.cause = options?.cause;\n this.name = this.constructor.name;\n this.details = [this.constructor.name, 'SerializableError'];\n }\n\n /*\n * Checks if the error is an instance of the current class or a subclass. Returns the error if it is.\n * We can't type the error as more than SerializableError because it could have been serialized and deserialized,\n * which could make it lose extra fields.\n */\n static inStackOf<T extends abstract new (...args: any) => any>(\n this: T,\n error: any,\n ): SerializableError | undefined {\n if (error?.details?.includes(this.name)) {\n return error as SerializableError;\n } else if (error?.cause?.details?.includes(this.name)) {\n return error.cause as SerializableError;\n }\n return undefined;\n }\n\n // We could limit this to only wrap serializable errors, but that could limit the flexibility of the error system.\n static wrap<T extends new (...args: any) => SerializableError>(\n this: T,\n error: any,\n // Remove the optional error arguments\n ...args: RemoveErrorOptions<ConstructorParameters<T>>\n ): InstanceType<T> {\n const wrappedError = new this(...args, { cause: error });\n\n wrappedError.details = error?.details\n ? [wrappedError.name, ...error.details]\n : [wrappedError.name, 'SerializableError', error?.name ?? 'UnknownError'];\n\n wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;\n\n return wrappedError as InstanceType<T>;\n }\n}\n\nexport class NonRetryableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\nexport class NotFoundError extends SerializableError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message ? `Not found: ${message}` : 'Not found', options);\n }\n}\n\n// TODO: extend this for chain specific providers\nexport class ProviderError extends SerializableError {\n constructor(providerUri: string, options?: ErrorOptions) {\n super(`Provider error at host '${ProviderError.parseHost(providerUri)}'`, options);\n }\n\n private static parseHost(providerUri: string): string {\n try {\n const url = new URL(providerUri);\n return url.host;\n } catch {\n return 'UNKNOWN_HOST';\n }\n }\n}\n\nexport class NonEmittableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'NonEmittableError';\n }\n}\n\nexport class QuorumNotAchievedYet extends SerializableError {\n constructor(options?: ErrorOptions) {\n super('The quorum was not achieved yet', options);\n }\n}\n\nexport class MultiError extends Error {\n constructor(public readonly errs: any[]) {\n super(errs.map((err) => err.message).join(', '));\n }\n}\n\nexport const throwError = <Err extends Error>(\n message: string,\n error?: (message: string) => Err,\n): never => {\n throw error?.(message) ?? new Error(message);\n};\n\n/**\n * Assert that a value is never.\n * Most useful for enforcing exhaustive switch statements.\n */\nexport const assertUnreachable = (value: never): never => {\n throw new NonRetryableError(`Unreachable value: ${value}`);\n};\n"]}
|
package/dist/errors.cjs
CHANGED
|
@@ -1,49 +1,53 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var MXJDS64O_cjs = require('./MXJDS64O.cjs');
|
|
4
4
|
require('./YJF4D23A.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "MultiError", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return MXJDS64O_cjs.MultiError; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "NonEmittableError", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return MXJDS64O_cjs.NonEmittableError; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "NonRetryableError", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return MXJDS64O_cjs.NonRetryableError; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "NotFoundError", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return MXJDS64O_cjs.NotFoundError; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "ProviderError", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return MXJDS64O_cjs.ProviderError; }
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "QuorumNotAchievedYet", {
|
|
29
29
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
30
|
+
get: function () { return MXJDS64O_cjs.QuorumNotAchievedYet; }
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "SerializableError", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
34
|
+
get: function () { return MXJDS64O_cjs.SerializableError; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "assertUnreachable", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return MXJDS64O_cjs.assertUnreachable; }
|
|
35
39
|
});
|
|
36
40
|
Object.defineProperty(exports, "convertErrorToObject", {
|
|
37
41
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
42
|
+
get: function () { return MXJDS64O_cjs.convertErrorToObject; }
|
|
39
43
|
});
|
|
40
44
|
Object.defineProperty(exports, "normalizeError", {
|
|
41
45
|
enumerable: true,
|
|
42
|
-
get: function () { return
|
|
46
|
+
get: function () { return MXJDS64O_cjs.normalizeError; }
|
|
43
47
|
});
|
|
44
48
|
Object.defineProperty(exports, "throwError", {
|
|
45
49
|
enumerable: true,
|
|
46
|
-
get: function () { return
|
|
50
|
+
get: function () { return MXJDS64O_cjs.throwError; }
|
|
47
51
|
});
|
|
48
52
|
//# sourceMappingURL=errors.cjs.map
|
|
49
53
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.d.ts
CHANGED
|
@@ -43,5 +43,10 @@ export declare class MultiError extends Error {
|
|
|
43
43
|
constructor(errs: any[]);
|
|
44
44
|
}
|
|
45
45
|
export declare const throwError: <Err extends Error>(message: string, error?: (message: string) => Err) => never;
|
|
46
|
+
/**
|
|
47
|
+
* Assert that a value is never.
|
|
48
|
+
* Most useful for enforcing exhaustive switch statements.
|
|
49
|
+
*/
|
|
50
|
+
export declare const assertUnreachable: (value: never) => never;
|
|
46
51
|
export {};
|
|
47
52
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAYA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAElD;AAED,wBAAgB,cAAc,CAAC,GAAG,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,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGtD;AAED,qBAAa,aAAc,SAAQ,iBAAiB;gBACpC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGvD;AAGD,qBAAa,aAAc,SAAQ,iBAAiB;gBACpC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAIvD,OAAO,CAAC,MAAM,CAAC,SAAS;CAQ3B;AAED,qBAAa,iBAAkB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAItD;AAED,qBAAa,oBAAqB,SAAQ,iBAAiB;gBAC3C,OAAO,CAAC,EAAE,YAAY;CAGrC;AAED,qBAAa,UAAW,SAAQ,KAAK;aACL,IAAI,EAAE,GAAG,EAAE;gBAAX,IAAI,EAAE,GAAG,EAAE;CAG1C;AAED,eAAO,MAAM,UAAU,GAAI,GAAG,SAAS,KAAK,EACxC,SAAS,MAAM,EACf,QAAQ,CAAC,OAAO,EAAE,MAAM,KAAK,GAAG,KACjC,KAEF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,KAAK,KAAG,KAEhD,CAAC"}
|
package/dist/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, convertErrorToObject, normalizeError, throwError } from './
|
|
1
|
+
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './HSJL4TXR.js';
|
|
2
2
|
import './VUOMXK5T.js';
|
|
3
3
|
//# sourceMappingURL=errors.js.map
|
|
4
4
|
//# sourceMappingURL=errors.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var MXJDS64O_cjs = require('./MXJDS64O.cjs');
|
|
4
4
|
var _4FQD32GO_cjs = require('./4FQD32GO.cjs');
|
|
5
5
|
require('./YJF4D23A.cjs');
|
|
6
6
|
|
|
@@ -8,43 +8,47 @@ require('./YJF4D23A.cjs');
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "MultiError", {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return MXJDS64O_cjs.MultiError; }
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "NonEmittableError", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
15
|
+
get: function () { return MXJDS64O_cjs.NonEmittableError; }
|
|
16
16
|
});
|
|
17
17
|
Object.defineProperty(exports, "NonRetryableError", {
|
|
18
18
|
enumerable: true,
|
|
19
|
-
get: function () { return
|
|
19
|
+
get: function () { return MXJDS64O_cjs.NonRetryableError; }
|
|
20
20
|
});
|
|
21
21
|
Object.defineProperty(exports, "NotFoundError", {
|
|
22
22
|
enumerable: true,
|
|
23
|
-
get: function () { return
|
|
23
|
+
get: function () { return MXJDS64O_cjs.NotFoundError; }
|
|
24
24
|
});
|
|
25
25
|
Object.defineProperty(exports, "ProviderError", {
|
|
26
26
|
enumerable: true,
|
|
27
|
-
get: function () { return
|
|
27
|
+
get: function () { return MXJDS64O_cjs.ProviderError; }
|
|
28
28
|
});
|
|
29
29
|
Object.defineProperty(exports, "QuorumNotAchievedYet", {
|
|
30
30
|
enumerable: true,
|
|
31
|
-
get: function () { return
|
|
31
|
+
get: function () { return MXJDS64O_cjs.QuorumNotAchievedYet; }
|
|
32
32
|
});
|
|
33
33
|
Object.defineProperty(exports, "SerializableError", {
|
|
34
34
|
enumerable: true,
|
|
35
|
-
get: function () { return
|
|
35
|
+
get: function () { return MXJDS64O_cjs.SerializableError; }
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "assertUnreachable", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return MXJDS64O_cjs.assertUnreachable; }
|
|
36
40
|
});
|
|
37
41
|
Object.defineProperty(exports, "convertErrorToObject", {
|
|
38
42
|
enumerable: true,
|
|
39
|
-
get: function () { return
|
|
43
|
+
get: function () { return MXJDS64O_cjs.convertErrorToObject; }
|
|
40
44
|
});
|
|
41
45
|
Object.defineProperty(exports, "normalizeError", {
|
|
42
46
|
enumerable: true,
|
|
43
|
-
get: function () { return
|
|
47
|
+
get: function () { return MXJDS64O_cjs.normalizeError; }
|
|
44
48
|
});
|
|
45
49
|
Object.defineProperty(exports, "throwError", {
|
|
46
50
|
enumerable: true,
|
|
47
|
-
get: function () { return
|
|
51
|
+
get: function () { return MXJDS64O_cjs.throwError; }
|
|
48
52
|
});
|
|
49
53
|
Object.defineProperty(exports, "runWithRetryPolicy", {
|
|
50
54
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, convertErrorToObject, normalizeError, throwError } from './
|
|
1
|
+
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './HSJL4TXR.js';
|
|
2
2
|
export { runWithRetryPolicy } from './ZLKJGRU2.js';
|
|
3
3
|
import './VUOMXK5T.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/common-error-utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"@types/ms": "^2.1.0",
|
|
22
22
|
"tsup": "^8.4.0",
|
|
23
23
|
"vitest": "^3.2.3",
|
|
24
|
-
"@layerzerolabs/tsup-configuration": "0.2.
|
|
25
|
-
"@layerzerolabs/typescript-configuration": "0.2.
|
|
24
|
+
"@layerzerolabs/tsup-configuration": "0.2.21",
|
|
25
|
+
"@layerzerolabs/typescript-configuration": "0.2.21"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "restricted",
|
package/src/errors.ts
CHANGED
|
@@ -143,3 +143,11 @@ export const throwError = <Err extends Error>(
|
|
|
143
143
|
): never => {
|
|
144
144
|
throw error?.(message) ?? new Error(message);
|
|
145
145
|
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Assert that a value is never.
|
|
149
|
+
* Most useful for enforcing exhaustive switch statements.
|
|
150
|
+
*/
|
|
151
|
+
export const assertUnreachable = (value: never): never => {
|
|
152
|
+
throw new NonRetryableError(`Unreachable value: ${value}`);
|
|
153
|
+
};
|
package/dist/W7EWJMEA.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts"],"names":["extractMessageFromJsonRpcError","err","body","message","parsedBody","JSON","parse","error","convertErrorToObject","stringify","Object","getOwnPropertyNames","normalizeError","name","stack","reason","code","event","SerializableError","Error","details","cause","options","inStackOf","includes","undefined","wrap","args","wrappedError","String","NonRetryableError","NotFoundError","ProviderError","providerUri","parseHost","url","URL","host","NonEmittableError","QuorumNotAchievedYet","MultiError","errs","map","join","throwError"],"mappings":";;;AAAA,IAAMA,8BAAAA,2BAAkCC,GAAAA,KAAAA;AACpC,EAAA,IAAI;AACA,IAAA,IAAI,OAAOA,GAAAA,CAAIC,IAAAA,KAAS,QAAA,IAAYD,GAAAA,CAAIC,KAAKC,OAAAA,EAAS;AAClD,MAAA,OAAOF,IAAIC,IAAAA,CAAKC,OAAAA;AACpB,IAAA;AACA,IAAA,MAAMC,UAAAA,GAAaC,IAAAA,CAAKC,KAAAA,CAAML,GAAAA,CAAI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CAAYf,SAAiBmB,OAAAA,EAAwB;AACjD,IAAA,KAAA,CAAMnB,SAASmB,OAAAA,CAAAA;AACf,IAAA,IAAA,CAAKT,IAAAA,GAAO,mBAAA;AAChB,EAAA;AACJ;AAEO,IAAM0B,oBAAAA,GAAN,cAAmCrB,iBAAAA,CAAAA;EA/H1C;;;AAgII,EAAA,WAAA,CAAYI,OAAAA,EAAwB;AAChC,IAAA,KAAA,CAAM,mCAAmCA,OAAAA,CAAAA;AAC7C,EAAA;AACJ;AAEO,IAAMkB,UAAAA,GAAN,cAAyBrB,KAAAA,CAAAA;EArIhC;;;;AAsII,EAAA,WAAA,CAA4BsB,IAAAA,EAAa;AACrC,IAAA,KAAA,CAAMA,IAAAA,CAAKC,GAAAA,CAAI,CAACzC,GAAAA,KAAQA,GAAAA,CAAIE,OAAO,CAAA,CAAEwC,IAAAA,CAAK,IAAA,CAAA,CAAA,EAAA,IAAA,CADlBF,IAAAA,GAAAA,IAAAA;AAE5B,EAAA;AACJ;AAEO,IAAMG,UAAAA,mBAAa,MAAA,CAAA,CACtBzC,OAAAA,EACAI,KAAAA,KAAAA;AAEA,EAAA,MAAMA,KAAAA,GAAQJ,OAAAA,CAAAA,IAAY,IAAIgB,MAAMhB,OAAAA,CAAAA;AACxC,CAAA,EAL0B,YAAA","file":"W7EWJMEA.js","sourcesContent":["const extractMessageFromJsonRpcError = (err: any): string => {\n try {\n if (typeof err.body === 'object' && err.body.message) {\n return err.body.message;\n }\n const parsedBody = JSON.parse(err.body);\n return parsedBody?.error?.message;\n } catch {\n return 'unknown';\n }\n};\n\nexport function convertErrorToObject(err: any): any {\n return JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err)));\n}\n\nexport function normalizeError(err: any) {\n const error = convertErrorToObject(err);\n return {\n // Normal Error properties\n ...(error.name ? { name: error.name } : {}),\n ...(error.message ? { message: error.message } : {}),\n ...(error.stack ? { stack: error.stack } : {}),\n // Rpc properties\n ...(error.reason ? { reason: error.reason } : {}),\n ...(error.code ? { code: error.code } : {}),\n ...(error.event ? { event: error.event } : {}),\n ...(error.body ? { body: extractMessageFromJsonRpcError(error) } : {}),\n };\n}\n\n// Removes the last argument if it is an ErrorOptions\ntype RemoveErrorOptions<T extends any[]> = T extends [...infer U, ErrorOptions?] ? U : never;\n\n/**\n * Base class for all serializable errors.\n * This class is designed to be extended by other error classes.\n * It provides a way to wrap errors and a way to check if an error is in the stack of a specific error class.\n * All errors that extend this class *must* have error options as the last argument in their constructor.\n */\nexport abstract class SerializableError extends Error {\n details: string[];\n /*\n * The instance of the error that was wrapped, if any.\n * Creates a linked list of error objects.\n * Only exists if the error hasn't been serialized and deserialized.\n */\n cause: unknown;\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n // for some reason, we need to set the cause directly on the instance, even after calling super\n this.cause = options?.cause;\n this.name = this.constructor.name;\n this.details = [this.constructor.name, 'SerializableError'];\n }\n\n /*\n * Checks if the error is an instance of the current class or a subclass. Returns the error if it is.\n * We can't type the error as more than SerializableError because it could have been serialized and deserialized,\n * which could make it lose extra fields.\n */\n static inStackOf<T extends abstract new (...args: any) => any>(\n this: T,\n error: any,\n ): SerializableError | undefined {\n if (error?.details?.includes(this.name)) {\n return error as SerializableError;\n } else if (error?.cause?.details?.includes(this.name)) {\n return error.cause as SerializableError;\n }\n return undefined;\n }\n\n // We could limit this to only wrap serializable errors, but that could limit the flexibility of the error system.\n static wrap<T extends new (...args: any) => SerializableError>(\n this: T,\n error: any,\n // Remove the optional error arguments\n ...args: RemoveErrorOptions<ConstructorParameters<T>>\n ): InstanceType<T> {\n const wrappedError = new this(...args, { cause: error });\n\n wrappedError.details = error?.details\n ? [wrappedError.name, ...error.details]\n : [wrappedError.name, 'SerializableError', error?.name ?? 'UnknownError'];\n\n wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;\n\n return wrappedError as InstanceType<T>;\n }\n}\n\nexport class NonRetryableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\nexport class NotFoundError extends SerializableError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message ? `Not found: ${message}` : 'Not found', options);\n }\n}\n\n// TODO: extend this for chain specific providers\nexport class ProviderError extends SerializableError {\n constructor(providerUri: string, options?: ErrorOptions) {\n super(`Provider error at host '${ProviderError.parseHost(providerUri)}'`, options);\n }\n\n private static parseHost(providerUri: string): string {\n try {\n const url = new URL(providerUri);\n return url.host;\n } catch {\n return 'UNKNOWN_HOST';\n }\n }\n}\n\nexport class NonEmittableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'NonEmittableError';\n }\n}\n\nexport class QuorumNotAchievedYet extends SerializableError {\n constructor(options?: ErrorOptions) {\n super('The quorum was not achieved yet', options);\n }\n}\n\nexport class MultiError extends Error {\n constructor(public readonly errs: any[]) {\n super(errs.map((err) => err.message).join(', '));\n }\n}\n\nexport const throwError = <Err extends Error>(\n message: string,\n error?: (message: string) => Err,\n): never => {\n throw error?.(message) ?? new Error(message);\n};\n"]}
|
package/dist/YBBPQS6P.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts"],"names":["extractMessageFromJsonRpcError","err","body","message","parsedBody","JSON","parse","error","convertErrorToObject","stringify","Object","getOwnPropertyNames","normalizeError","name","stack","reason","code","event","SerializableError","Error","details","cause","options","inStackOf","includes","undefined","wrap","args","wrappedError","String","NonRetryableError","NotFoundError","ProviderError","providerUri","parseHost","url","URL","host","NonEmittableError","QuorumNotAchievedYet","MultiError","errs","map","join","throwError","__name"],"mappings":";;;;;AAAA,IAAMA,8BAAAA,wCAAkCC,GAAAA,KAAAA;AACpC,EAAA,IAAI;AACA,IAAA,IAAI,OAAOA,GAAAA,CAAIC,IAAAA,KAAS,QAAA,IAAYD,GAAAA,CAAIC,KAAKC,OAAAA,EAAS;AAClD,MAAA,OAAOF,IAAIC,IAAAA,CAAKC,OAAAA;AACpB,IAAA;AACA,IAAA,MAAM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AN,cAAgCpB,iBAAAA,CAAAA;EAxHvC;;;AAyHI,EAAA,WAAA,CAAYf,SAAiBmB,OAAAA,EAAwB;AACjD,IAAA,KAAA,CAAMnB,SAASmB,OAAAA,CAAAA;AACf,IAAA,IAAA,CAAKT,IAAAA,GAAO,mBAAA;AAChB,EAAA;AACJ;AAEO,IAAM0B,oBAAAA,GAAN,cAAmCrB,iBAAAA,CAAAA;EA/H1C;;;AAgII,EAAA,WAAA,CAAYI,OAAAA,EAAwB;AAChC,IAAA,KAAA,CAAM,mCAAmCA,OAAAA,CAAAA;AAC7C,EAAA;AACJ;AAEO,IAAMkB,UAAAA,GAAN,cAAyBrB,KAAAA,CAAAA;EArIhC;;;;AAsII,EAAA,WAAA,CAA4BsB,IAAAA,EAAa;AACrC,IAAA,KAAA,CAAMA,IAAAA,CAAKC,GAAAA,CAAI,CAACzC,GAAAA,KAAQA,GAAAA,CAAIE,OAAO,CAAA,CAAEwC,IAAAA,CAAK,IAAA,CAAA,CAAA,EAAA,IAAA,CADlBF,IAAAA,GAAAA,IAAAA;AAE5B,EAAA;AACJ;AAEO,IAAMG,UAAAA,mBAAaC,mBAAA,CAAA,CACtB1C,OAAAA,EACAI,KAAAA,KAAAA;AAEA,EAAA,MAAMA,KAAAA,GAAQJ,OAAAA,CAAAA,IAAY,IAAIgB,MAAMhB,OAAAA,CAAAA;AACxC,CAAA,EAL0B,YAAA","file":"YBBPQS6P.cjs","sourcesContent":["const extractMessageFromJsonRpcError = (err: any): string => {\n try {\n if (typeof err.body === 'object' && err.body.message) {\n return err.body.message;\n }\n const parsedBody = JSON.parse(err.body);\n return parsedBody?.error?.message;\n } catch {\n return 'unknown';\n }\n};\n\nexport function convertErrorToObject(err: any): any {\n return JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err)));\n}\n\nexport function normalizeError(err: any) {\n const error = convertErrorToObject(err);\n return {\n // Normal Error properties\n ...(error.name ? { name: error.name } : {}),\n ...(error.message ? { message: error.message } : {}),\n ...(error.stack ? { stack: error.stack } : {}),\n // Rpc properties\n ...(error.reason ? { reason: error.reason } : {}),\n ...(error.code ? { code: error.code } : {}),\n ...(error.event ? { event: error.event } : {}),\n ...(error.body ? { body: extractMessageFromJsonRpcError(error) } : {}),\n };\n}\n\n// Removes the last argument if it is an ErrorOptions\ntype RemoveErrorOptions<T extends any[]> = T extends [...infer U, ErrorOptions?] ? U : never;\n\n/**\n * Base class for all serializable errors.\n * This class is designed to be extended by other error classes.\n * It provides a way to wrap errors and a way to check if an error is in the stack of a specific error class.\n * All errors that extend this class *must* have error options as the last argument in their constructor.\n */\nexport abstract class SerializableError extends Error {\n details: string[];\n /*\n * The instance of the error that was wrapped, if any.\n * Creates a linked list of error objects.\n * Only exists if the error hasn't been serialized and deserialized.\n */\n cause: unknown;\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n // for some reason, we need to set the cause directly on the instance, even after calling super\n this.cause = options?.cause;\n this.name = this.constructor.name;\n this.details = [this.constructor.name, 'SerializableError'];\n }\n\n /*\n * Checks if the error is an instance of the current class or a subclass. Returns the error if it is.\n * We can't type the error as more than SerializableError because it could have been serialized and deserialized,\n * which could make it lose extra fields.\n */\n static inStackOf<T extends abstract new (...args: any) => any>(\n this: T,\n error: any,\n ): SerializableError | undefined {\n if (error?.details?.includes(this.name)) {\n return error as SerializableError;\n } else if (error?.cause?.details?.includes(this.name)) {\n return error.cause as SerializableError;\n }\n return undefined;\n }\n\n // We could limit this to only wrap serializable errors, but that could limit the flexibility of the error system.\n static wrap<T extends new (...args: any) => SerializableError>(\n this: T,\n error: any,\n // Remove the optional error arguments\n ...args: RemoveErrorOptions<ConstructorParameters<T>>\n ): InstanceType<T> {\n const wrappedError = new this(...args, { cause: error });\n\n wrappedError.details = error?.details\n ? [wrappedError.name, ...error.details]\n : [wrappedError.name, 'SerializableError', error?.name ?? 'UnknownError'];\n\n wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;\n\n return wrappedError as InstanceType<T>;\n }\n}\n\nexport class NonRetryableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\nexport class NotFoundError extends SerializableError {\n constructor(message?: string, options?: ErrorOptions) {\n super(message ? `Not found: ${message}` : 'Not found', options);\n }\n}\n\n// TODO: extend this for chain specific providers\nexport class ProviderError extends SerializableError {\n constructor(providerUri: string, options?: ErrorOptions) {\n super(`Provider error at host '${ProviderError.parseHost(providerUri)}'`, options);\n }\n\n private static parseHost(providerUri: string): string {\n try {\n const url = new URL(providerUri);\n return url.host;\n } catch {\n return 'UNKNOWN_HOST';\n }\n }\n}\n\nexport class NonEmittableError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'NonEmittableError';\n }\n}\n\nexport class QuorumNotAchievedYet extends SerializableError {\n constructor(options?: ErrorOptions) {\n super('The quorum was not achieved yet', options);\n }\n}\n\nexport class MultiError extends Error {\n constructor(public readonly errs: any[]) {\n super(errs.map((err) => err.message).join(', '));\n }\n}\n\nexport const throwError = <Err extends Error>(\n message: string,\n error?: (message: string) => Err,\n): never => {\n throw error?.(message) ?? new Error(message);\n};\n"]}
|