@layerzerolabs/common-error-utils 0.2.86 → 0.2.87
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/dist/{MXJDS64O.cjs → 4HBD5QMD.cjs} +34 -11
- package/dist/4HBD5QMD.cjs.map +1 -0
- package/dist/{HSJL4TXR.js → EZMQCLO2.js} +34 -12
- package/dist/EZMQCLO2.js.map +1 -0
- package/dist/errors.cjs +16 -12
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.cjs +16 -12
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/HSJL4TXR.js.map +0 -1
- package/dist/MXJDS64O.cjs.map +0 -1
|
@@ -47,7 +47,7 @@ function normalizeError(err) {
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
YJF4D23A_cjs.__name(normalizeError, "normalizeError");
|
|
50
|
-
var SerializableError = class extends Error {
|
|
50
|
+
var SerializableError = class _SerializableError extends Error {
|
|
51
51
|
static {
|
|
52
52
|
YJF4D23A_cjs.__name(this, "SerializableError");
|
|
53
53
|
}
|
|
@@ -62,10 +62,22 @@ var SerializableError = class extends Error {
|
|
|
62
62
|
super(message, options);
|
|
63
63
|
this.cause = options?.cause;
|
|
64
64
|
this.name = this.constructor.name;
|
|
65
|
-
this.details =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
];
|
|
65
|
+
this.details = _SerializableError.computeClassChain(this);
|
|
66
|
+
}
|
|
67
|
+
static computeClassChain(instance) {
|
|
68
|
+
const chain = [];
|
|
69
|
+
let proto = Object.getPrototypeOf(instance);
|
|
70
|
+
while (proto && proto !== Error.prototype && proto !== Object.prototype) {
|
|
71
|
+
const name = proto.constructor?.name;
|
|
72
|
+
if (name) {
|
|
73
|
+
chain.push(name);
|
|
74
|
+
}
|
|
75
|
+
if (name === _SerializableError.name) {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
proto = Object.getPrototypeOf(proto);
|
|
79
|
+
}
|
|
80
|
+
return chain;
|
|
69
81
|
}
|
|
70
82
|
/*
|
|
71
83
|
* Checks if the error is an instance of the current class or a subclass. Returns the error if it is.
|
|
@@ -85,14 +97,16 @@ var SerializableError = class extends Error {
|
|
|
85
97
|
const wrappedError = new this(...args, {
|
|
86
98
|
cause: error
|
|
87
99
|
});
|
|
88
|
-
|
|
89
|
-
wrappedError.
|
|
100
|
+
const combinedDetails = error?.details ? [
|
|
101
|
+
...wrappedError.details,
|
|
90
102
|
...error.details
|
|
91
103
|
] : [
|
|
92
|
-
wrappedError.
|
|
93
|
-
"SerializableError",
|
|
104
|
+
...wrappedError.details,
|
|
94
105
|
error?.name ?? "UnknownError"
|
|
95
106
|
];
|
|
107
|
+
wrappedError.details = [
|
|
108
|
+
...new Set(combinedDetails)
|
|
109
|
+
];
|
|
96
110
|
wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;
|
|
97
111
|
return wrappedError;
|
|
98
112
|
}
|
|
@@ -105,6 +119,14 @@ var NonRetryableError = class extends SerializableError {
|
|
|
105
119
|
super(message, options);
|
|
106
120
|
}
|
|
107
121
|
};
|
|
122
|
+
var ActivityNotAvailableError = class extends NonRetryableError {
|
|
123
|
+
static {
|
|
124
|
+
YJF4D23A_cjs.__name(this, "ActivityNotAvailableError");
|
|
125
|
+
}
|
|
126
|
+
constructor(message, options) {
|
|
127
|
+
super(message, options);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
108
130
|
var NotFoundError = class extends SerializableError {
|
|
109
131
|
static {
|
|
110
132
|
YJF4D23A_cjs.__name(this, "NotFoundError");
|
|
@@ -162,6 +184,7 @@ var assertUnreachable = /* @__PURE__ */ YJF4D23A_cjs.__name((value) => {
|
|
|
162
184
|
throw new NonRetryableError(`Unreachable value: ${value}`);
|
|
163
185
|
}, "assertUnreachable");
|
|
164
186
|
|
|
187
|
+
exports.ActivityNotAvailableError = ActivityNotAvailableError;
|
|
165
188
|
exports.MultiError = MultiError;
|
|
166
189
|
exports.NonEmittableError = NonEmittableError;
|
|
167
190
|
exports.NonRetryableError = NonRetryableError;
|
|
@@ -173,5 +196,5 @@ exports.assertUnreachable = assertUnreachable;
|
|
|
173
196
|
exports.convertErrorToObject = convertErrorToObject;
|
|
174
197
|
exports.normalizeError = normalizeError;
|
|
175
198
|
exports.throwError = throwError;
|
|
176
|
-
//# sourceMappingURL=
|
|
177
|
-
//# sourceMappingURL=
|
|
199
|
+
//# sourceMappingURL=4HBD5QMD.cjs.map
|
|
200
|
+
//# sourceMappingURL=4HBD5QMD.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","computeClassChain","instance","chain","proto","getPrototypeOf","prototype","push","inStackOf","includes","undefined","wrap","args","wrappedError","combinedDetails","Set","String","NonRetryableError","ActivityNotAvailableError","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;AAY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,IAAAA,CAAK,IAAA,CAAA,CAAA,EAAA,IAAA,CADlBF,IAAAA,GAAAA,IAAAA;AAE5B,EAAA;AACJ;AAEO,IAAMG,UAAAA,mBAAaC,mBAAA,CAAA,CACtBpD,OAAAA,EACAI,KAAAA,KAAAA;AAEA,EAAA,MAAMA,KAAAA,GAAQJ,OAAAA,CAAAA,IAAY,IAAIgB,MAAMhB,OAAAA,CAAAA;AACxC,CAAA,EAL0B,YAAA;AAWnB,IAAMqD,iBAAAA,wCAAqBC,KAAAA,KAAAA;AAC9B,EAAA,MAAM,IAAIlB,iBAAAA,CAAkB,CAAA,mBAAA,EAAsBkB,KAAAA,CAAAA,CAAO,CAAA;AAC7D,CAAA,EAFiC,mBAAA","file":"4HBD5QMD.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 = SerializableError.computeClassChain(this);\n }\n\n private static computeClassChain(instance: SerializableError): string[] {\n const chain: string[] = [];\n let proto: object | null = Object.getPrototypeOf(instance);\n while (proto && proto !== Error.prototype && proto !== Object.prototype) {\n const name = proto.constructor?.name;\n if (name) {\n chain.push(name);\n }\n if (name === SerializableError.name) {\n break;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return chain;\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 const combinedDetails = error?.details\n ? [...wrappedError.details, ...error.details]\n : [...wrappedError.details, error?.name ?? 'UnknownError'];\n wrappedError.details = [...new Set(combinedDetails)];\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 ActivityNotAvailableError extends NonRetryableError {\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"]}
|
|
@@ -45,7 +45,7 @@ function normalizeError(err) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
__name(normalizeError, "normalizeError");
|
|
48
|
-
var SerializableError = class extends Error {
|
|
48
|
+
var SerializableError = class _SerializableError extends Error {
|
|
49
49
|
static {
|
|
50
50
|
__name(this, "SerializableError");
|
|
51
51
|
}
|
|
@@ -60,10 +60,22 @@ var SerializableError = class extends Error {
|
|
|
60
60
|
super(message, options);
|
|
61
61
|
this.cause = options?.cause;
|
|
62
62
|
this.name = this.constructor.name;
|
|
63
|
-
this.details =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
];
|
|
63
|
+
this.details = _SerializableError.computeClassChain(this);
|
|
64
|
+
}
|
|
65
|
+
static computeClassChain(instance) {
|
|
66
|
+
const chain = [];
|
|
67
|
+
let proto = Object.getPrototypeOf(instance);
|
|
68
|
+
while (proto && proto !== Error.prototype && proto !== Object.prototype) {
|
|
69
|
+
const name = proto.constructor?.name;
|
|
70
|
+
if (name) {
|
|
71
|
+
chain.push(name);
|
|
72
|
+
}
|
|
73
|
+
if (name === _SerializableError.name) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
proto = Object.getPrototypeOf(proto);
|
|
77
|
+
}
|
|
78
|
+
return chain;
|
|
67
79
|
}
|
|
68
80
|
/*
|
|
69
81
|
* Checks if the error is an instance of the current class or a subclass. Returns the error if it is.
|
|
@@ -83,14 +95,16 @@ var SerializableError = class extends Error {
|
|
|
83
95
|
const wrappedError = new this(...args, {
|
|
84
96
|
cause: error
|
|
85
97
|
});
|
|
86
|
-
|
|
87
|
-
wrappedError.
|
|
98
|
+
const combinedDetails = error?.details ? [
|
|
99
|
+
...wrappedError.details,
|
|
88
100
|
...error.details
|
|
89
101
|
] : [
|
|
90
|
-
wrappedError.
|
|
91
|
-
"SerializableError",
|
|
102
|
+
...wrappedError.details,
|
|
92
103
|
error?.name ?? "UnknownError"
|
|
93
104
|
];
|
|
105
|
+
wrappedError.details = [
|
|
106
|
+
...new Set(combinedDetails)
|
|
107
|
+
];
|
|
94
108
|
wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;
|
|
95
109
|
return wrappedError;
|
|
96
110
|
}
|
|
@@ -103,6 +117,14 @@ var NonRetryableError = class extends SerializableError {
|
|
|
103
117
|
super(message, options);
|
|
104
118
|
}
|
|
105
119
|
};
|
|
120
|
+
var ActivityNotAvailableError = class extends NonRetryableError {
|
|
121
|
+
static {
|
|
122
|
+
__name(this, "ActivityNotAvailableError");
|
|
123
|
+
}
|
|
124
|
+
constructor(message, options) {
|
|
125
|
+
super(message, options);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
106
128
|
var NotFoundError = class extends SerializableError {
|
|
107
129
|
static {
|
|
108
130
|
__name(this, "NotFoundError");
|
|
@@ -160,6 +182,6 @@ var assertUnreachable = /* @__PURE__ */ __name((value) => {
|
|
|
160
182
|
throw new NonRetryableError(`Unreachable value: ${value}`);
|
|
161
183
|
}, "assertUnreachable");
|
|
162
184
|
|
|
163
|
-
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError };
|
|
164
|
-
//# sourceMappingURL=
|
|
165
|
-
//# sourceMappingURL=
|
|
185
|
+
export { ActivityNotAvailableError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError };
|
|
186
|
+
//# sourceMappingURL=EZMQCLO2.js.map
|
|
187
|
+
//# sourceMappingURL=EZMQCLO2.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","computeClassChain","instance","chain","proto","getPrototypeOf","prototype","push","inStackOf","includes","undefined","wrap","args","wrappedError","combinedDetails","Set","String","NonRetryableError","ActivityNotAvailableError","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,EAAO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rC,IAAA,KAAA,CAAMA,IAAAA,CAAKC,GAAAA,CAAI,CAACnD,GAAAA,KAAQA,GAAAA,CAAIE,OAAO,CAAA,CAAEkD,IAAAA,CAAK,IAAA,CAAA,CAAA,EAAA,IAAA,CADlBF,IAAAA,GAAAA,IAAAA;AAE5B,EAAA;AACJ;AAEO,IAAMG,UAAAA,mBAAa,MAAA,CAAA,CACtBnD,OAAAA,EACAI,KAAAA,KAAAA;AAEA,EAAA,MAAMA,KAAAA,GAAQJ,OAAAA,CAAAA,IAAY,IAAIgB,MAAMhB,OAAAA,CAAAA;AACxC,CAAA,EAL0B,YAAA;AAWnB,IAAMoD,iBAAAA,2BAAqBC,KAAAA,KAAAA;AAC9B,EAAA,MAAM,IAAIjB,iBAAAA,CAAkB,CAAA,mBAAA,EAAsBiB,KAAAA,CAAAA,CAAO,CAAA;AAC7D,CAAA,EAFiC,mBAAA","file":"EZMQCLO2.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 = SerializableError.computeClassChain(this);\n }\n\n private static computeClassChain(instance: SerializableError): string[] {\n const chain: string[] = [];\n let proto: object | null = Object.getPrototypeOf(instance);\n while (proto && proto !== Error.prototype && proto !== Object.prototype) {\n const name = proto.constructor?.name;\n if (name) {\n chain.push(name);\n }\n if (name === SerializableError.name) {\n break;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return chain;\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 const combinedDetails = error?.details\n ? [...wrappedError.details, ...error.details]\n : [...wrappedError.details, error?.name ?? 'UnknownError'];\n wrappedError.details = [...new Set(combinedDetails)];\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 ActivityNotAvailableError extends NonRetryableError {\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,53 +1,57 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _4HBD5QMD_cjs = require('./4HBD5QMD.cjs');
|
|
4
4
|
require('./YJF4D23A.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
Object.defineProperty(exports, "ActivityNotAvailableError", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return _4HBD5QMD_cjs.ActivityNotAvailableError; }
|
|
11
|
+
});
|
|
8
12
|
Object.defineProperty(exports, "MultiError", {
|
|
9
13
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
14
|
+
get: function () { return _4HBD5QMD_cjs.MultiError; }
|
|
11
15
|
});
|
|
12
16
|
Object.defineProperty(exports, "NonEmittableError", {
|
|
13
17
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
18
|
+
get: function () { return _4HBD5QMD_cjs.NonEmittableError; }
|
|
15
19
|
});
|
|
16
20
|
Object.defineProperty(exports, "NonRetryableError", {
|
|
17
21
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
22
|
+
get: function () { return _4HBD5QMD_cjs.NonRetryableError; }
|
|
19
23
|
});
|
|
20
24
|
Object.defineProperty(exports, "NotFoundError", {
|
|
21
25
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
26
|
+
get: function () { return _4HBD5QMD_cjs.NotFoundError; }
|
|
23
27
|
});
|
|
24
28
|
Object.defineProperty(exports, "ProviderError", {
|
|
25
29
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
30
|
+
get: function () { return _4HBD5QMD_cjs.ProviderError; }
|
|
27
31
|
});
|
|
28
32
|
Object.defineProperty(exports, "QuorumNotAchievedYet", {
|
|
29
33
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
34
|
+
get: function () { return _4HBD5QMD_cjs.QuorumNotAchievedYet; }
|
|
31
35
|
});
|
|
32
36
|
Object.defineProperty(exports, "SerializableError", {
|
|
33
37
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
38
|
+
get: function () { return _4HBD5QMD_cjs.SerializableError; }
|
|
35
39
|
});
|
|
36
40
|
Object.defineProperty(exports, "assertUnreachable", {
|
|
37
41
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
42
|
+
get: function () { return _4HBD5QMD_cjs.assertUnreachable; }
|
|
39
43
|
});
|
|
40
44
|
Object.defineProperty(exports, "convertErrorToObject", {
|
|
41
45
|
enumerable: true,
|
|
42
|
-
get: function () { return
|
|
46
|
+
get: function () { return _4HBD5QMD_cjs.convertErrorToObject; }
|
|
43
47
|
});
|
|
44
48
|
Object.defineProperty(exports, "normalizeError", {
|
|
45
49
|
enumerable: true,
|
|
46
|
-
get: function () { return
|
|
50
|
+
get: function () { return _4HBD5QMD_cjs.normalizeError; }
|
|
47
51
|
});
|
|
48
52
|
Object.defineProperty(exports, "throwError", {
|
|
49
53
|
enumerable: true,
|
|
50
|
-
get: function () { return
|
|
54
|
+
get: function () { return _4HBD5QMD_cjs.throwError; }
|
|
51
55
|
});
|
|
52
56
|
//# sourceMappingURL=errors.cjs.map
|
|
53
57
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.d.ts
CHANGED
|
@@ -19,12 +19,16 @@ export declare abstract class SerializableError extends Error {
|
|
|
19
19
|
details: string[];
|
|
20
20
|
cause: unknown;
|
|
21
21
|
constructor(message: string, options?: ErrorOptions);
|
|
22
|
+
private static computeClassChain;
|
|
22
23
|
static inStackOf<T extends abstract new (...args: any) => any>(this: T, error: any): SerializableError | undefined;
|
|
23
24
|
static wrap<T extends new (...args: any) => SerializableError>(this: T, error: any, ...args: RemoveErrorOptions<ConstructorParameters<T>>): InstanceType<T>;
|
|
24
25
|
}
|
|
25
26
|
export declare class NonRetryableError extends SerializableError {
|
|
26
27
|
constructor(message: string, options?: ErrorOptions);
|
|
27
28
|
}
|
|
29
|
+
export declare class ActivityNotAvailableError extends NonRetryableError {
|
|
30
|
+
constructor(message: string, options?: ErrorOptions);
|
|
31
|
+
}
|
|
28
32
|
export declare class NotFoundError extends SerializableError {
|
|
29
33
|
constructor(message?: string, options?: ErrorOptions);
|
|
30
34
|
}
|
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,EAAE,GAAG;;;;;;;;EAatC;AAGD,KAAK,kBAAkB,CAAC,CAAC,SAAS,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CAAC,CAAC;CAYrB;AAED,qBAAa,iBAAkB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGtD;AAED,qBAAa,yBAA0B,SAAQ,iBAAiB;gBAChD,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, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './
|
|
1
|
+
export { ActivityNotAvailableError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './EZMQCLO2.js';
|
|
2
2
|
import './VUOMXK5T.js';
|
|
3
3
|
//# sourceMappingURL=errors.js.map
|
|
4
4
|
//# sourceMappingURL=errors.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,54 +1,58 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _4HBD5QMD_cjs = require('./4HBD5QMD.cjs');
|
|
4
4
|
var CSP5OI2I_cjs = require('./CSP5OI2I.cjs');
|
|
5
5
|
require('./YJF4D23A.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
Object.defineProperty(exports, "ActivityNotAvailableError", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return _4HBD5QMD_cjs.ActivityNotAvailableError; }
|
|
12
|
+
});
|
|
9
13
|
Object.defineProperty(exports, "MultiError", {
|
|
10
14
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
15
|
+
get: function () { return _4HBD5QMD_cjs.MultiError; }
|
|
12
16
|
});
|
|
13
17
|
Object.defineProperty(exports, "NonEmittableError", {
|
|
14
18
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
19
|
+
get: function () { return _4HBD5QMD_cjs.NonEmittableError; }
|
|
16
20
|
});
|
|
17
21
|
Object.defineProperty(exports, "NonRetryableError", {
|
|
18
22
|
enumerable: true,
|
|
19
|
-
get: function () { return
|
|
23
|
+
get: function () { return _4HBD5QMD_cjs.NonRetryableError; }
|
|
20
24
|
});
|
|
21
25
|
Object.defineProperty(exports, "NotFoundError", {
|
|
22
26
|
enumerable: true,
|
|
23
|
-
get: function () { return
|
|
27
|
+
get: function () { return _4HBD5QMD_cjs.NotFoundError; }
|
|
24
28
|
});
|
|
25
29
|
Object.defineProperty(exports, "ProviderError", {
|
|
26
30
|
enumerable: true,
|
|
27
|
-
get: function () { return
|
|
31
|
+
get: function () { return _4HBD5QMD_cjs.ProviderError; }
|
|
28
32
|
});
|
|
29
33
|
Object.defineProperty(exports, "QuorumNotAchievedYet", {
|
|
30
34
|
enumerable: true,
|
|
31
|
-
get: function () { return
|
|
35
|
+
get: function () { return _4HBD5QMD_cjs.QuorumNotAchievedYet; }
|
|
32
36
|
});
|
|
33
37
|
Object.defineProperty(exports, "SerializableError", {
|
|
34
38
|
enumerable: true,
|
|
35
|
-
get: function () { return
|
|
39
|
+
get: function () { return _4HBD5QMD_cjs.SerializableError; }
|
|
36
40
|
});
|
|
37
41
|
Object.defineProperty(exports, "assertUnreachable", {
|
|
38
42
|
enumerable: true,
|
|
39
|
-
get: function () { return
|
|
43
|
+
get: function () { return _4HBD5QMD_cjs.assertUnreachable; }
|
|
40
44
|
});
|
|
41
45
|
Object.defineProperty(exports, "convertErrorToObject", {
|
|
42
46
|
enumerable: true,
|
|
43
|
-
get: function () { return
|
|
47
|
+
get: function () { return _4HBD5QMD_cjs.convertErrorToObject; }
|
|
44
48
|
});
|
|
45
49
|
Object.defineProperty(exports, "normalizeError", {
|
|
46
50
|
enumerable: true,
|
|
47
|
-
get: function () { return
|
|
51
|
+
get: function () { return _4HBD5QMD_cjs.normalizeError; }
|
|
48
52
|
});
|
|
49
53
|
Object.defineProperty(exports, "throwError", {
|
|
50
54
|
enumerable: true,
|
|
51
|
-
get: function () { return
|
|
55
|
+
get: function () { return _4HBD5QMD_cjs.throwError; }
|
|
52
56
|
});
|
|
53
57
|
Object.defineProperty(exports, "runWithRetryPolicy", {
|
|
54
58
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './
|
|
1
|
+
export { ActivityNotAvailableError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './EZMQCLO2.js';
|
|
2
2
|
export { runWithRetryPolicy } from './WUDCWRMR.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.87",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@types/ms": "^2.1.0",
|
|
25
25
|
"tsup": "^8.4.0",
|
|
26
26
|
"vitest": "^3.2.3",
|
|
27
|
-
"@layerzerolabs/tsup-configuration": "0.2.
|
|
28
|
-
"@layerzerolabs/typescript-configuration": "0.2.
|
|
27
|
+
"@layerzerolabs/tsup-configuration": "0.2.87",
|
|
28
|
+
"@layerzerolabs/typescript-configuration": "0.2.87"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public",
|
package/dist/HSJL4TXR.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","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,I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,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,mBAAa,MAAA,CAAA,CACtBzC,OAAAA,EACAI,KAAAA,KAAAA;AAEA,EAAA,MAAMA,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"]}
|
package/dist/MXJDS64O.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","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;;AAE5C,IAAA,GA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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"]}
|