@layerzerolabs/common-error-utils 0.2.8 → 0.2.9
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 +27 -7
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +6 -5
- package/dist/4FQD32GO.cjs +41 -0
- package/dist/4FQD32GO.cjs.map +1 -0
- package/dist/VUOMXK5T.js +6 -0
- package/dist/VUOMXK5T.js.map +1 -0
- package/dist/W7EWJMEA.js +162 -0
- package/dist/W7EWJMEA.js.map +1 -0
- package/dist/YBBPQS6P.cjs +173 -0
- package/dist/YBBPQS6P.cjs.map +1 -0
- package/dist/YJF4D23A.cjs +8 -0
- package/dist/YJF4D23A.cjs.map +1 -0
- package/dist/ZLKJGRU2.js +35 -0
- package/dist/ZLKJGRU2.js.map +1 -0
- package/dist/errors.cjs +49 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +47 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +48 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -46
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -161
- package/dist/index.js.map +1 -1
- package/dist/retry.cjs +13 -0
- package/dist/retry.cjs.map +1 -0
- package/dist/retry.d.ts +54 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +4 -0
- package/dist/retry.js.map +1 -0
- package/package.json +8 -3
- package/src/errors.ts +145 -0
- package/src/index.ts +2 -145
- package/src/retry.ts +101 -0
- package/tests/retry.test.ts +110 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
> @layerzerolabs/common-error-utils@0.0.0 build /home/runner/work/monorepo-internal/monorepo-internal/packages/common/common-error-utils
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
5
|
+
[34mCLI[39m Building entry: src/errors.ts, src/index.ts, src/retry.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.1
|
|
8
8
|
[34mCLI[39m Using tsup config: /home/runner/work/monorepo-internal/monorepo-internal/packages/common/common-error-utils/tsup.config.ts
|
|
@@ -10,9 +10,29 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
12
|
[34mESM[39m Build start
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[32mCJS[39m [1mdist/
|
|
17
|
-
[32mCJS[39m [1mdist/
|
|
18
|
-
[32mCJS[39m
|
|
13
|
+
[32mCJS[39m [1mdist/errors.cjs [22m[32m1.49 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m1.67 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/YJF4D23A.cjs [22m[32m245.00 B[39m
|
|
16
|
+
[32mCJS[39m [1mdist/YBBPQS6P.cjs [22m[32m4.86 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/4FQD32GO.cjs [22m[32m1.65 KB[39m
|
|
18
|
+
[32mCJS[39m [1mdist/retry.cjs [22m[32m304.00 B[39m
|
|
19
|
+
[32mCJS[39m [1mdist/errors.cjs.map [22m[32m71.00 B[39m
|
|
20
|
+
[32mCJS[39m [1mdist/YJF4D23A.cjs.map [22m[32m73.00 B[39m
|
|
21
|
+
[32mCJS[39m [1mdist/YBBPQS6P.cjs.map [22m[32m9.79 KB[39m
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m70.00 B[39m
|
|
23
|
+
[32mCJS[39m [1mdist/4FQD32GO.cjs.map [22m[32m5.24 KB[39m
|
|
24
|
+
[32mCJS[39m [1mdist/retry.cjs.map [22m[32m70.00 B[39m
|
|
25
|
+
[32mCJS[39m ⚡️ Build success in 161ms
|
|
26
|
+
[32mESM[39m [1mdist/errors.js [22m[32m296.00 B[39m
|
|
27
|
+
[32mESM[39m [1mdist/index.js [22m[32m346.00 B[39m
|
|
28
|
+
[32mESM[39m [1mdist/W7EWJMEA.js [22m[32m4.46 KB[39m
|
|
29
|
+
[32mESM[39m [1mdist/ZLKJGRU2.js [22m[32m1.37 KB[39m
|
|
30
|
+
[32mESM[39m [1mdist/retry.js [22m[32m143.00 B[39m
|
|
31
|
+
[32mESM[39m [1mdist/VUOMXK5T.js [22m[32m222.00 B[39m
|
|
32
|
+
[32mESM[39m [1mdist/errors.js.map [22m[32m70.00 B[39m
|
|
33
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m69.00 B[39m
|
|
34
|
+
[32mESM[39m [1mdist/W7EWJMEA.js.map [22m[32m9.77 KB[39m
|
|
35
|
+
[32mESM[39m [1mdist/ZLKJGRU2.js.map [22m[32m5.22 KB[39m
|
|
36
|
+
[32mESM[39m [1mdist/retry.js.map [22m[32m69.00 B[39m
|
|
37
|
+
[32mESM[39m [1mdist/VUOMXK5T.js.map [22m[32m72.00 B[39m
|
|
38
|
+
[32mESM[39m ⚡️ Build success in 161ms
|
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:28735) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1767136335616 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,11 +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
|
|
25
|
+
[32m✓[39m tests/error.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 15[2mms[22m[39m
|
|
26
|
+
[32m✓[39m tests/retry.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 76[2mms[22m[39m
|
|
26
27
|
|
|
27
|
-
[2m Test Files [22m [1m[
|
|
28
|
-
[2m Tests [22m [1m[
|
|
28
|
+
[2m Test Files [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
|
29
|
+
[2m Tests [22m [1m[32m9 passed[39m[22m[90m (9)[39m
|
|
29
30
|
[2mType Errors [22m [2mno errors[22m
|
|
30
|
-
[2m Start at [22m
|
|
31
|
-
[2m Duration [22m
|
|
31
|
+
[2m Start at [22m 23:17:28
|
|
32
|
+
[2m Duration [22m 731ms[2m (transform 247ms, setup 0ms, collect 443ms, tests 90ms, environment 1ms, prepare 328ms)[22m
|
|
32
33
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var YJF4D23A_cjs = require('./YJF4D23A.cjs');
|
|
4
|
+
var exponentialBackoff = require('exponential-backoff');
|
|
5
|
+
var ms = require('ms');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var ms__default = /*#__PURE__*/_interopDefault(ms);
|
|
10
|
+
|
|
11
|
+
var DEFAULT_NONRETRYABLE_ERRORS = [
|
|
12
|
+
"NonRetryableError"
|
|
13
|
+
];
|
|
14
|
+
var runWithRetryPolicy = /* @__PURE__ */ YJF4D23A_cjs.__name((fn, policy, shouldRetry) => {
|
|
15
|
+
const perTryTimeout = ms__default.default(policy?.startToCloseTimeout ?? "10 minutes");
|
|
16
|
+
const numOfAttempts = policy?.maximumAttempts ?? Infinity;
|
|
17
|
+
const startingDelay = ms__default.default(policy?.initialInterval ?? "1s");
|
|
18
|
+
const maxDelay = policy?.maximumInterval ? ms__default.default(policy.maximumInterval) : startingDelay * 100;
|
|
19
|
+
const timeMultiple = Math.max(policy?.backoffCoefficient ?? 2, 1);
|
|
20
|
+
const nonRetryableErrorTypes = (policy?.nonRetryableErrorTypes ?? []).concat(DEFAULT_NONRETRYABLE_ERRORS);
|
|
21
|
+
return exponentialBackoff.backOff(() => new Promise((resolve, reject) => {
|
|
22
|
+
fn().then(resolve).catch(reject);
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
reject(new Error(`Execution timed out after ${perTryTimeout}ms`));
|
|
25
|
+
}, perTryTimeout);
|
|
26
|
+
}), {
|
|
27
|
+
maxDelay,
|
|
28
|
+
startingDelay,
|
|
29
|
+
jitter: "full",
|
|
30
|
+
timeMultiple,
|
|
31
|
+
numOfAttempts,
|
|
32
|
+
retry: /* @__PURE__ */ YJF4D23A_cjs.__name(async (error) => {
|
|
33
|
+
const errorType = error?.constructor?.name ?? error?.name;
|
|
34
|
+
return !nonRetryableErrorTypes.includes(errorType) && (shouldRetry ? shouldRetry(error) : true);
|
|
35
|
+
}, "retry")
|
|
36
|
+
});
|
|
37
|
+
}, "runWithRetryPolicy");
|
|
38
|
+
|
|
39
|
+
exports.runWithRetryPolicy = runWithRetryPolicy;
|
|
40
|
+
//# sourceMappingURL=4FQD32GO.cjs.map
|
|
41
|
+
//# sourceMappingURL=4FQD32GO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/retry.ts"],"names":["DEFAULT_NONRETRYABLE_ERRORS","runWithRetryPolicy","__name","fn","policy","shouldRetry","perTryTimeout","ms","startToCloseTimeout","numOfAttempts","maximumAttempts","Infinity","startingDelay","initialInterval","maxDelay","maximumInterval","timeMultiple","Math","max","backoffCoefficient","nonRetryableErrorTypes","concat","backOff","Promise","resolve","reject","then","catch","setTimeout","Error","jitter","retry","error","errorType","name","includes"],"mappings":";;;;;;;;;;AAIA,IAAMA,2BAAAA,GAA8B;AAAC,EAAA;;AA2D9B,IAAMC,kBAAAA,mBAAqBC,mBAAA,CAAA,CAC9BC,EAAAA,EACAC,MAAAA,EACAC,WAAAA,KAAAA;AAEA,EAAA,MAAMC,aAAAA,GAAgBC,mBAAAA,CAAGH,MAAAA,EAAQI,mBAAAA,IAAuB,YAAA,CAAA;AACxD,EAAA,MAAMC,aAAAA,GAAgBL,QAAQM,eAAAA,IAAmBC,QAAAA;AACjD,EAAA,MAAMC,aAAAA,GAAgBL,mBAAAA,CAAGH,MAAAA,EAAQS,eAAAA,IAAmB,IAAA,CAAA;AACpD,EAAA,MAAMC,WAAWV,MAAAA,EAAQW,eAAAA,GAAkBR,oBAAGH,MAAAA,CAAOW,eAAe,IAAIH,aAAAA,GAAgB,GAAA;AACxF,EAAA,MAAMI,eAAeC,IAAAA,CAAKC,GAAAA,CAAId,MAAAA,EAAQe,kBAAAA,IAAsB,GAAG,CAAA,CAAA;AAC/D,EAAA,MAAMC,0BAA0BhB,MAAAA,EAAQgB,sBAAAA,IAA0B,EAAA,EAAIC,OAClErB,2BAAAA,CAAAA;AAGJ,EAAA,OAAOsB,2BACH,MACI,IAAIC,OAAAA,CAAQ,CAACC,SAASC,MAAAA,KAAAA;AAClBtB,IAAAA,EAAAA,EAAAA,CAAKuB,IAAAA,CAAKF,OAAAA,CAAAA,CAASG,MAAMF,MAAAA,CAAAA;AACzBG,IAAAA,UAAAA,CAAW,MAAA;AACPH,MAAAA,MAAAA,CAAO,IAAII,KAAAA,CAAM,CAAA,0BAAA,EAA6BvB,aAAAA,IAAiB,CAAA,CAAA;AACnE,IAAA,CAAA,EAAGA,aAAAA,CAAAA;AACP,EAAA,CAAA,CAAA,EACJ;AACIQ,IAAAA,QAAAA;AACAF,IAAAA,aAAAA;IACAkB,MAAAA,EAAQ,MAAA;AACRd,IAAAA,YAAAA;AACAP,IAAAA,aAAAA;AACAsB,IAAAA,KAAAA,6CAAcC,KAAAA,KAAAA;AACV,MAAA,MAAMC,SAAAA,GAAYD,KAAAA,EAAO,WAAA,EAAaE,IAAAA,IAAQF,KAAAA,EAAOE,IAAAA;AACrD,MAAA,OACI,CAACd,uBAAuBe,QAAAA,CAASF,SAAAA,MAChC5B,WAAAA,GAAcA,WAAAA,CAAY2B,KAAAA,CAAAA,GAAS,IAAA,CAAA;IAE5C,CAAA,EANO,OAAA;GAOX,CAAA;AAER,CAAA,EArCkC,oBAAA","file":"4FQD32GO.cjs","sourcesContent":["import { backOff } from 'exponential-backoff';\nimport type { StringValue } from 'ms';\nimport ms from 'ms';\n\nconst DEFAULT_NONRETRYABLE_ERRORS = ['NonRetryableError'];\n\nexport interface RetryPolicy {\n /**\n * Maximum time of a single execution attempt.\n * This timeout should be as short as the longest possible execution of the Activity body.\n *\n * @default 10 minutes\n * @format {@link https://www.npmjs.com/package/ms | ms-formatted string}\n */\n startToCloseTimeout?: StringValue;\n\n /**\n * Coefficient used to calculate the next retry interval.\n * The next retry interval is previous interval multiplied by this coefficient.\n * @minimum 1\n * @default 2\n */\n backoffCoefficient?: number;\n\n /**\n * Interval of the first retry.\n * If coefficient is 1 then it is used for all retries\n * @format {@link https://www.npmjs.com/package/ms | ms-formatted string}\n * @default 1 second\n */\n initialInterval?: StringValue;\n\n /**\n * Maximum number of attempts. When exceeded, retries stop.\n *\n * @default Infinity\n */\n maximumAttempts?: number;\n\n /**\n * Maximum interval between retries.\n * Exponential backoff leads to interval increase.\n * This value is the cap of the increase.\n *\n * @default 100x of {@link initialInterval}\n * @format {@link https://www.npmjs.com/package/ms | ms-formatted string}\n */\n maximumInterval?: StringValue;\n\n /**\n * List of application failures types to not retry.\n */\n nonRetryableErrorTypes?: string[];\n}\n\n/**\n * Executes a function with a retry policy.\n * @param fn - The function to execute.\n * @param policy - The retry policy to apply.\n * @param shouldRetry - A callback that determines if the error is retryable besides the nonRetryableErrorTypes.\n * @return A promise that resolves to the result of the function or rejects with an error.\n * @throws Error if the function fails after all retries.\n */\nexport const runWithRetryPolicy = <T = unknown>(\n fn: () => Promise<T>,\n policy?: RetryPolicy,\n shouldRetry?: (err: any) => boolean,\n): Promise<T> => {\n const perTryTimeout = ms(policy?.startToCloseTimeout ?? '10 minutes');\n const numOfAttempts = policy?.maximumAttempts ?? Infinity;\n const startingDelay = ms(policy?.initialInterval ?? '1s');\n const maxDelay = policy?.maximumInterval ? ms(policy.maximumInterval) : startingDelay * 100;\n const timeMultiple = Math.max(policy?.backoffCoefficient ?? 2, 1);\n const nonRetryableErrorTypes = (policy?.nonRetryableErrorTypes ?? []).concat(\n DEFAULT_NONRETRYABLE_ERRORS,\n );\n\n return backOff(\n () =>\n new Promise((resolve, reject) => {\n fn().then(resolve).catch(reject);\n setTimeout(() => {\n reject(new Error(`Execution timed out after ${perTryTimeout}ms`));\n }, perTryTimeout);\n }),\n {\n maxDelay,\n startingDelay,\n jitter: 'full',\n timeMultiple,\n numOfAttempts,\n retry: async (error: any) => {\n const errorType = error?.constructor?.name ?? error?.name;\n return (\n !nonRetryableErrorTypes.includes(errorType) &&\n (shouldRetry ? shouldRetry(error) : true)\n );\n },\n },\n );\n};\n"]}
|
package/dist/VUOMXK5T.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"VUOMXK5T.js"}
|
package/dist/W7EWJMEA.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { __name } from './VUOMXK5T.js';
|
|
2
|
+
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
var extractMessageFromJsonRpcError = /* @__PURE__ */ __name((err) => {
|
|
5
|
+
try {
|
|
6
|
+
if (typeof err.body === "object" && err.body.message) {
|
|
7
|
+
return err.body.message;
|
|
8
|
+
}
|
|
9
|
+
const parsedBody = JSON.parse(err.body);
|
|
10
|
+
return parsedBody?.error?.message;
|
|
11
|
+
} catch {
|
|
12
|
+
return "unknown";
|
|
13
|
+
}
|
|
14
|
+
}, "extractMessageFromJsonRpcError");
|
|
15
|
+
function convertErrorToObject(err) {
|
|
16
|
+
return JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err)));
|
|
17
|
+
}
|
|
18
|
+
__name(convertErrorToObject, "convertErrorToObject");
|
|
19
|
+
function normalizeError(err) {
|
|
20
|
+
const error = convertErrorToObject(err);
|
|
21
|
+
return {
|
|
22
|
+
// Normal Error properties
|
|
23
|
+
...error.name ? {
|
|
24
|
+
name: error.name
|
|
25
|
+
} : {},
|
|
26
|
+
...error.message ? {
|
|
27
|
+
message: error.message
|
|
28
|
+
} : {},
|
|
29
|
+
...error.stack ? {
|
|
30
|
+
stack: error.stack
|
|
31
|
+
} : {},
|
|
32
|
+
// Rpc properties
|
|
33
|
+
...error.reason ? {
|
|
34
|
+
reason: error.reason
|
|
35
|
+
} : {},
|
|
36
|
+
...error.code ? {
|
|
37
|
+
code: error.code
|
|
38
|
+
} : {},
|
|
39
|
+
...error.event ? {
|
|
40
|
+
event: error.event
|
|
41
|
+
} : {},
|
|
42
|
+
...error.body ? {
|
|
43
|
+
body: extractMessageFromJsonRpcError(error)
|
|
44
|
+
} : {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
__name(normalizeError, "normalizeError");
|
|
48
|
+
var SerializableError = class extends Error {
|
|
49
|
+
static {
|
|
50
|
+
__name(this, "SerializableError");
|
|
51
|
+
}
|
|
52
|
+
details;
|
|
53
|
+
/*
|
|
54
|
+
* The instance of the error that was wrapped, if any.
|
|
55
|
+
* Creates a linked list of error objects.
|
|
56
|
+
* Only exists if the error hasn't been serialized and deserialized.
|
|
57
|
+
*/
|
|
58
|
+
cause;
|
|
59
|
+
constructor(message, options) {
|
|
60
|
+
super(message, options);
|
|
61
|
+
this.cause = options?.cause;
|
|
62
|
+
this.name = this.constructor.name;
|
|
63
|
+
this.details = [
|
|
64
|
+
this.constructor.name,
|
|
65
|
+
"SerializableError"
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
/*
|
|
69
|
+
* Checks if the error is an instance of the current class or a subclass. Returns the error if it is.
|
|
70
|
+
* We can't type the error as more than SerializableError because it could have been serialized and deserialized,
|
|
71
|
+
* which could make it lose extra fields.
|
|
72
|
+
*/
|
|
73
|
+
static inStackOf(error) {
|
|
74
|
+
if (error?.details?.includes(this.name)) {
|
|
75
|
+
return error;
|
|
76
|
+
} else if (error?.cause?.details?.includes(this.name)) {
|
|
77
|
+
return error.cause;
|
|
78
|
+
}
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
// We could limit this to only wrap serializable errors, but that could limit the flexibility of the error system.
|
|
82
|
+
static wrap(error, ...args) {
|
|
83
|
+
const wrappedError = new this(...args, {
|
|
84
|
+
cause: error
|
|
85
|
+
});
|
|
86
|
+
wrappedError.details = error?.details ? [
|
|
87
|
+
wrappedError.name,
|
|
88
|
+
...error.details
|
|
89
|
+
] : [
|
|
90
|
+
wrappedError.name,
|
|
91
|
+
"SerializableError",
|
|
92
|
+
error?.name ?? "UnknownError"
|
|
93
|
+
];
|
|
94
|
+
wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;
|
|
95
|
+
return wrappedError;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var NonRetryableError = class extends SerializableError {
|
|
99
|
+
static {
|
|
100
|
+
__name(this, "NonRetryableError");
|
|
101
|
+
}
|
|
102
|
+
constructor(message, options) {
|
|
103
|
+
super(message, options);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var NotFoundError = class extends SerializableError {
|
|
107
|
+
static {
|
|
108
|
+
__name(this, "NotFoundError");
|
|
109
|
+
}
|
|
110
|
+
constructor(message, options) {
|
|
111
|
+
super(message ? `Not found: ${message}` : "Not found", options);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var ProviderError = class _ProviderError extends SerializableError {
|
|
115
|
+
static {
|
|
116
|
+
__name(this, "ProviderError");
|
|
117
|
+
}
|
|
118
|
+
constructor(providerUri, options) {
|
|
119
|
+
super(`Provider error at host '${_ProviderError.parseHost(providerUri)}'`, options);
|
|
120
|
+
}
|
|
121
|
+
static parseHost(providerUri) {
|
|
122
|
+
try {
|
|
123
|
+
const url = new URL(providerUri);
|
|
124
|
+
return url.host;
|
|
125
|
+
} catch {
|
|
126
|
+
return "UNKNOWN_HOST";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var NonEmittableError = class extends SerializableError {
|
|
131
|
+
static {
|
|
132
|
+
__name(this, "NonEmittableError");
|
|
133
|
+
}
|
|
134
|
+
constructor(message, options) {
|
|
135
|
+
super(message, options);
|
|
136
|
+
this.name = "NonEmittableError";
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var QuorumNotAchievedYet = class extends SerializableError {
|
|
140
|
+
static {
|
|
141
|
+
__name(this, "QuorumNotAchievedYet");
|
|
142
|
+
}
|
|
143
|
+
constructor(options) {
|
|
144
|
+
super("The quorum was not achieved yet", options);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var MultiError = class extends Error {
|
|
148
|
+
static {
|
|
149
|
+
__name(this, "MultiError");
|
|
150
|
+
}
|
|
151
|
+
errs;
|
|
152
|
+
constructor(errs) {
|
|
153
|
+
super(errs.map((err) => err.message).join(", ")), this.errs = errs;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var throwError = /* @__PURE__ */ __name((message, error) => {
|
|
157
|
+
throw error?.(message) ?? new Error(message);
|
|
158
|
+
}, "throwError");
|
|
159
|
+
|
|
160
|
+
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, convertErrorToObject, normalizeError, throwError };
|
|
161
|
+
//# sourceMappingURL=W7EWJMEA.js.map
|
|
162
|
+
//# sourceMappingURL=W7EWJMEA.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"],"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,MAAM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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"]}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var YJF4D23A_cjs = require('./YJF4D23A.cjs');
|
|
4
|
+
|
|
5
|
+
// src/errors.ts
|
|
6
|
+
var extractMessageFromJsonRpcError = /* @__PURE__ */ YJF4D23A_cjs.__name((err) => {
|
|
7
|
+
try {
|
|
8
|
+
if (typeof err.body === "object" && err.body.message) {
|
|
9
|
+
return err.body.message;
|
|
10
|
+
}
|
|
11
|
+
const parsedBody = JSON.parse(err.body);
|
|
12
|
+
return parsedBody?.error?.message;
|
|
13
|
+
} catch {
|
|
14
|
+
return "unknown";
|
|
15
|
+
}
|
|
16
|
+
}, "extractMessageFromJsonRpcError");
|
|
17
|
+
function convertErrorToObject(err) {
|
|
18
|
+
return JSON.parse(JSON.stringify(err, Object.getOwnPropertyNames(err)));
|
|
19
|
+
}
|
|
20
|
+
YJF4D23A_cjs.__name(convertErrorToObject, "convertErrorToObject");
|
|
21
|
+
function normalizeError(err) {
|
|
22
|
+
const error = convertErrorToObject(err);
|
|
23
|
+
return {
|
|
24
|
+
// Normal Error properties
|
|
25
|
+
...error.name ? {
|
|
26
|
+
name: error.name
|
|
27
|
+
} : {},
|
|
28
|
+
...error.message ? {
|
|
29
|
+
message: error.message
|
|
30
|
+
} : {},
|
|
31
|
+
...error.stack ? {
|
|
32
|
+
stack: error.stack
|
|
33
|
+
} : {},
|
|
34
|
+
// Rpc properties
|
|
35
|
+
...error.reason ? {
|
|
36
|
+
reason: error.reason
|
|
37
|
+
} : {},
|
|
38
|
+
...error.code ? {
|
|
39
|
+
code: error.code
|
|
40
|
+
} : {},
|
|
41
|
+
...error.event ? {
|
|
42
|
+
event: error.event
|
|
43
|
+
} : {},
|
|
44
|
+
...error.body ? {
|
|
45
|
+
body: extractMessageFromJsonRpcError(error)
|
|
46
|
+
} : {}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
YJF4D23A_cjs.__name(normalizeError, "normalizeError");
|
|
50
|
+
var SerializableError = class extends Error {
|
|
51
|
+
static {
|
|
52
|
+
YJF4D23A_cjs.__name(this, "SerializableError");
|
|
53
|
+
}
|
|
54
|
+
details;
|
|
55
|
+
/*
|
|
56
|
+
* The instance of the error that was wrapped, if any.
|
|
57
|
+
* Creates a linked list of error objects.
|
|
58
|
+
* Only exists if the error hasn't been serialized and deserialized.
|
|
59
|
+
*/
|
|
60
|
+
cause;
|
|
61
|
+
constructor(message, options) {
|
|
62
|
+
super(message, options);
|
|
63
|
+
this.cause = options?.cause;
|
|
64
|
+
this.name = this.constructor.name;
|
|
65
|
+
this.details = [
|
|
66
|
+
this.constructor.name,
|
|
67
|
+
"SerializableError"
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
/*
|
|
71
|
+
* Checks if the error is an instance of the current class or a subclass. Returns the error if it is.
|
|
72
|
+
* We can't type the error as more than SerializableError because it could have been serialized and deserialized,
|
|
73
|
+
* which could make it lose extra fields.
|
|
74
|
+
*/
|
|
75
|
+
static inStackOf(error) {
|
|
76
|
+
if (error?.details?.includes(this.name)) {
|
|
77
|
+
return error;
|
|
78
|
+
} else if (error?.cause?.details?.includes(this.name)) {
|
|
79
|
+
return error.cause;
|
|
80
|
+
}
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
// We could limit this to only wrap serializable errors, but that could limit the flexibility of the error system.
|
|
84
|
+
static wrap(error, ...args) {
|
|
85
|
+
const wrappedError = new this(...args, {
|
|
86
|
+
cause: error
|
|
87
|
+
});
|
|
88
|
+
wrappedError.details = error?.details ? [
|
|
89
|
+
wrappedError.name,
|
|
90
|
+
...error.details
|
|
91
|
+
] : [
|
|
92
|
+
wrappedError.name,
|
|
93
|
+
"SerializableError",
|
|
94
|
+
error?.name ?? "UnknownError"
|
|
95
|
+
];
|
|
96
|
+
wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;
|
|
97
|
+
return wrappedError;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var NonRetryableError = class extends SerializableError {
|
|
101
|
+
static {
|
|
102
|
+
YJF4D23A_cjs.__name(this, "NonRetryableError");
|
|
103
|
+
}
|
|
104
|
+
constructor(message, options) {
|
|
105
|
+
super(message, options);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var NotFoundError = class extends SerializableError {
|
|
109
|
+
static {
|
|
110
|
+
YJF4D23A_cjs.__name(this, "NotFoundError");
|
|
111
|
+
}
|
|
112
|
+
constructor(message, options) {
|
|
113
|
+
super(message ? `Not found: ${message}` : "Not found", options);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var ProviderError = class _ProviderError extends SerializableError {
|
|
117
|
+
static {
|
|
118
|
+
YJF4D23A_cjs.__name(this, "ProviderError");
|
|
119
|
+
}
|
|
120
|
+
constructor(providerUri, options) {
|
|
121
|
+
super(`Provider error at host '${_ProviderError.parseHost(providerUri)}'`, options);
|
|
122
|
+
}
|
|
123
|
+
static parseHost(providerUri) {
|
|
124
|
+
try {
|
|
125
|
+
const url = new URL(providerUri);
|
|
126
|
+
return url.host;
|
|
127
|
+
} catch {
|
|
128
|
+
return "UNKNOWN_HOST";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var NonEmittableError = class extends SerializableError {
|
|
133
|
+
static {
|
|
134
|
+
YJF4D23A_cjs.__name(this, "NonEmittableError");
|
|
135
|
+
}
|
|
136
|
+
constructor(message, options) {
|
|
137
|
+
super(message, options);
|
|
138
|
+
this.name = "NonEmittableError";
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var QuorumNotAchievedYet = class extends SerializableError {
|
|
142
|
+
static {
|
|
143
|
+
YJF4D23A_cjs.__name(this, "QuorumNotAchievedYet");
|
|
144
|
+
}
|
|
145
|
+
constructor(options) {
|
|
146
|
+
super("The quorum was not achieved yet", options);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var MultiError = class extends Error {
|
|
150
|
+
static {
|
|
151
|
+
YJF4D23A_cjs.__name(this, "MultiError");
|
|
152
|
+
}
|
|
153
|
+
errs;
|
|
154
|
+
constructor(errs) {
|
|
155
|
+
super(errs.map((err) => err.message).join(", ")), this.errs = errs;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var throwError = /* @__PURE__ */ YJF4D23A_cjs.__name((message, error) => {
|
|
159
|
+
throw error?.(message) ?? new Error(message);
|
|
160
|
+
}, "throwError");
|
|
161
|
+
|
|
162
|
+
exports.MultiError = MultiError;
|
|
163
|
+
exports.NonEmittableError = NonEmittableError;
|
|
164
|
+
exports.NonRetryableError = NonRetryableError;
|
|
165
|
+
exports.NotFoundError = NotFoundError;
|
|
166
|
+
exports.ProviderError = ProviderError;
|
|
167
|
+
exports.QuorumNotAchievedYet = QuorumNotAchievedYet;
|
|
168
|
+
exports.SerializableError = SerializableError;
|
|
169
|
+
exports.convertErrorToObject = convertErrorToObject;
|
|
170
|
+
exports.normalizeError = normalizeError;
|
|
171
|
+
exports.throwError = throwError;
|
|
172
|
+
//# sourceMappingURL=YBBPQS6P.cjs.map
|
|
173
|
+
//# sourceMappingURL=YBBPQS6P.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"],"mappings":";;;;;AAAA,IAAMA,8BAAAA,wCAAkCC,GAAAA,KAAAA;AACpC,EAAA,IAAI;AACA,IAAA,IAAI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IH,WAAAA,CAAAA;AACpB,MAAA,OAAOE,GAAAA,CAAIE,IAAAA;IACf,CAAA,CAAA,MAAQ;AACJ,MAAA,OAAO,cAAA;AACX,IAAA;AACJ,EAAA;AACJ;AAEO,IAAMC,iBAAAA,GAAN,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"YJF4D23A.cjs"}
|
package/dist/ZLKJGRU2.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { __name } from './VUOMXK5T.js';
|
|
2
|
+
import { backOff } from 'exponential-backoff';
|
|
3
|
+
import ms from 'ms';
|
|
4
|
+
|
|
5
|
+
var DEFAULT_NONRETRYABLE_ERRORS = [
|
|
6
|
+
"NonRetryableError"
|
|
7
|
+
];
|
|
8
|
+
var runWithRetryPolicy = /* @__PURE__ */ __name((fn, policy, shouldRetry) => {
|
|
9
|
+
const perTryTimeout = ms(policy?.startToCloseTimeout ?? "10 minutes");
|
|
10
|
+
const numOfAttempts = policy?.maximumAttempts ?? Infinity;
|
|
11
|
+
const startingDelay = ms(policy?.initialInterval ?? "1s");
|
|
12
|
+
const maxDelay = policy?.maximumInterval ? ms(policy.maximumInterval) : startingDelay * 100;
|
|
13
|
+
const timeMultiple = Math.max(policy?.backoffCoefficient ?? 2, 1);
|
|
14
|
+
const nonRetryableErrorTypes = (policy?.nonRetryableErrorTypes ?? []).concat(DEFAULT_NONRETRYABLE_ERRORS);
|
|
15
|
+
return backOff(() => new Promise((resolve, reject) => {
|
|
16
|
+
fn().then(resolve).catch(reject);
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
reject(new Error(`Execution timed out after ${perTryTimeout}ms`));
|
|
19
|
+
}, perTryTimeout);
|
|
20
|
+
}), {
|
|
21
|
+
maxDelay,
|
|
22
|
+
startingDelay,
|
|
23
|
+
jitter: "full",
|
|
24
|
+
timeMultiple,
|
|
25
|
+
numOfAttempts,
|
|
26
|
+
retry: /* @__PURE__ */ __name(async (error) => {
|
|
27
|
+
const errorType = error?.constructor?.name ?? error?.name;
|
|
28
|
+
return !nonRetryableErrorTypes.includes(errorType) && (shouldRetry ? shouldRetry(error) : true);
|
|
29
|
+
}, "retry")
|
|
30
|
+
});
|
|
31
|
+
}, "runWithRetryPolicy");
|
|
32
|
+
|
|
33
|
+
export { runWithRetryPolicy };
|
|
34
|
+
//# sourceMappingURL=ZLKJGRU2.js.map
|
|
35
|
+
//# sourceMappingURL=ZLKJGRU2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/retry.ts"],"names":["DEFAULT_NONRETRYABLE_ERRORS","runWithRetryPolicy","fn","policy","shouldRetry","perTryTimeout","ms","startToCloseTimeout","numOfAttempts","maximumAttempts","Infinity","startingDelay","initialInterval","maxDelay","maximumInterval","timeMultiple","Math","max","backoffCoefficient","nonRetryableErrorTypes","concat","backOff","Promise","resolve","reject","then","catch","setTimeout","Error","jitter","retry","error","errorType","name","includes"],"mappings":";;;;AAIA,IAAMA,2BAAAA,GAA8B;AAAC,EAAA;;AA2D9B,IAAMC,kBAAAA,mBAAqB,MAAA,CAAA,CAC9BC,EAAAA,EACAC,MAAAA,EACAC,WAAAA,KAAAA;AAEA,EAAA,MAAMC,aAAAA,GAAgBC,EAAAA,CAAGH,MAAAA,EAAQI,mBAAAA,IAAuB,YAAA,CAAA;AACxD,EAAA,MAAMC,aAAAA,GAAgBL,QAAQM,eAAAA,IAAmBC,QAAAA;AACjD,EAAA,MAAMC,aAAAA,GAAgBL,EAAAA,CAAGH,MAAAA,EAAQS,eAAAA,IAAmB,IAAA,CAAA;AACpD,EAAA,MAAMC,WAAWV,MAAAA,EAAQW,eAAAA,GAAkBR,GAAGH,MAAAA,CAAOW,eAAe,IAAIH,aAAAA,GAAgB,GAAA;AACxF,EAAA,MAAMI,eAAeC,IAAAA,CAAKC,GAAAA,CAAId,MAAAA,EAAQe,kBAAAA,IAAsB,GAAG,CAAA,CAAA;AAC/D,EAAA,MAAMC,0BAA0BhB,MAAAA,EAAQgB,sBAAAA,IAA0B,EAAA,EAAIC,OAClEpB,2BAAAA,CAAAA;AAGJ,EAAA,OAAOqB,QACH,MACI,IAAIC,OAAAA,CAAQ,CAACC,SAASC,MAAAA,KAAAA;AAClBtB,IAAAA,EAAAA,EAAAA,CAAKuB,IAAAA,CAAKF,OAAAA,CAAAA,CAASG,MAAMF,MAAAA,CAAAA;AACzBG,IAAAA,UAAAA,CAAW,MAAA;AACPH,MAAAA,MAAAA,CAAO,IAAII,KAAAA,CAAM,CAAA,0BAAA,EAA6BvB,aAAAA,IAAiB,CAAA,CAAA;AACnE,IAAA,CAAA,EAAGA,aAAAA,CAAAA;AACP,EAAA,CAAA,CAAA,EACJ;AACIQ,IAAAA,QAAAA;AACAF,IAAAA,aAAAA;IACAkB,MAAAA,EAAQ,MAAA;AACRd,IAAAA,YAAAA;AACAP,IAAAA,aAAAA;AACAsB,IAAAA,KAAAA,gCAAcC,KAAAA,KAAAA;AACV,MAAA,MAAMC,SAAAA,GAAYD,KAAAA,EAAO,WAAA,EAAaE,IAAAA,IAAQF,KAAAA,EAAOE,IAAAA;AACrD,MAAA,OACI,CAACd,uBAAuBe,QAAAA,CAASF,SAAAA,MAChC5B,WAAAA,GAAcA,WAAAA,CAAY2B,KAAAA,CAAAA,GAAS,IAAA,CAAA;IAE5C,CAAA,EANO,OAAA;GAOX,CAAA;AAER,CAAA,EArCkC,oBAAA","file":"ZLKJGRU2.js","sourcesContent":["import { backOff } from 'exponential-backoff';\nimport type { StringValue } from 'ms';\nimport ms from 'ms';\n\nconst DEFAULT_NONRETRYABLE_ERRORS = ['NonRetryableError'];\n\nexport interface RetryPolicy {\n /**\n * Maximum time of a single execution attempt.\n * This timeout should be as short as the longest possible execution of the Activity body.\n *\n * @default 10 minutes\n * @format {@link https://www.npmjs.com/package/ms | ms-formatted string}\n */\n startToCloseTimeout?: StringValue;\n\n /**\n * Coefficient used to calculate the next retry interval.\n * The next retry interval is previous interval multiplied by this coefficient.\n * @minimum 1\n * @default 2\n */\n backoffCoefficient?: number;\n\n /**\n * Interval of the first retry.\n * If coefficient is 1 then it is used for all retries\n * @format {@link https://www.npmjs.com/package/ms | ms-formatted string}\n * @default 1 second\n */\n initialInterval?: StringValue;\n\n /**\n * Maximum number of attempts. When exceeded, retries stop.\n *\n * @default Infinity\n */\n maximumAttempts?: number;\n\n /**\n * Maximum interval between retries.\n * Exponential backoff leads to interval increase.\n * This value is the cap of the increase.\n *\n * @default 100x of {@link initialInterval}\n * @format {@link https://www.npmjs.com/package/ms | ms-formatted string}\n */\n maximumInterval?: StringValue;\n\n /**\n * List of application failures types to not retry.\n */\n nonRetryableErrorTypes?: string[];\n}\n\n/**\n * Executes a function with a retry policy.\n * @param fn - The function to execute.\n * @param policy - The retry policy to apply.\n * @param shouldRetry - A callback that determines if the error is retryable besides the nonRetryableErrorTypes.\n * @return A promise that resolves to the result of the function or rejects with an error.\n * @throws Error if the function fails after all retries.\n */\nexport const runWithRetryPolicy = <T = unknown>(\n fn: () => Promise<T>,\n policy?: RetryPolicy,\n shouldRetry?: (err: any) => boolean,\n): Promise<T> => {\n const perTryTimeout = ms(policy?.startToCloseTimeout ?? '10 minutes');\n const numOfAttempts = policy?.maximumAttempts ?? Infinity;\n const startingDelay = ms(policy?.initialInterval ?? '1s');\n const maxDelay = policy?.maximumInterval ? ms(policy.maximumInterval) : startingDelay * 100;\n const timeMultiple = Math.max(policy?.backoffCoefficient ?? 2, 1);\n const nonRetryableErrorTypes = (policy?.nonRetryableErrorTypes ?? []).concat(\n DEFAULT_NONRETRYABLE_ERRORS,\n );\n\n return backOff(\n () =>\n new Promise((resolve, reject) => {\n fn().then(resolve).catch(reject);\n setTimeout(() => {\n reject(new Error(`Execution timed out after ${perTryTimeout}ms`));\n }, perTryTimeout);\n }),\n {\n maxDelay,\n startingDelay,\n jitter: 'full',\n timeMultiple,\n numOfAttempts,\n retry: async (error: any) => {\n const errorType = error?.constructor?.name ?? error?.name;\n return (\n !nonRetryableErrorTypes.includes(errorType) &&\n (shouldRetry ? shouldRetry(error) : true)\n );\n },\n },\n );\n};\n"]}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var YBBPQS6P_cjs = require('./YBBPQS6P.cjs');
|
|
4
|
+
require('./YJF4D23A.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "MultiError", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return YBBPQS6P_cjs.MultiError; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "NonEmittableError", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return YBBPQS6P_cjs.NonEmittableError; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "NonRetryableError", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return YBBPQS6P_cjs.NonRetryableError; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "NotFoundError", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return YBBPQS6P_cjs.NotFoundError; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "ProviderError", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return YBBPQS6P_cjs.ProviderError; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "QuorumNotAchievedYet", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return YBBPQS6P_cjs.QuorumNotAchievedYet; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "SerializableError", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return YBBPQS6P_cjs.SerializableError; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "convertErrorToObject", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return YBBPQS6P_cjs.convertErrorToObject; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "normalizeError", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return YBBPQS6P_cjs.normalizeError; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "throwError", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return YBBPQS6P_cjs.throwError; }
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=errors.cjs.map
|
|
49
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"errors.cjs"}
|