@layerzerolabs/common-error-utils 1.2.45 → 1.2.47

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.
@@ -90,6 +90,20 @@ var SerializableError = class _SerializableError extends Error {
90
90
  }
91
91
  return void 0;
92
92
  }
93
+ /*
94
+ * Constructs this error and marks it non-retryable, e.g. AssertionError.nonRetryable('...').
95
+ * Being non-retryable is a modifier rather than a kind of error, so prefer this over extending
96
+ * NonRetryableError. Retry policies match on the exact class name and not the prototype chain,
97
+ * so a subclass is silently retried unless its own name is registered in every policy.
98
+ * The result keeps this error's class chain in details, so inStackOf still narrows to it.
99
+ */
100
+ static nonRetryable(...args) {
101
+ const error = new this(...args);
102
+ if (error.constructor === NonRetryableError) {
103
+ return error;
104
+ }
105
+ return NonRetryableError.wrap(error, "");
106
+ }
93
107
  // We could limit this to only wrap serializable errors, but that could limit the flexibility of the error system.
94
108
  static wrap(error, ...args) {
95
109
  const wrappedError = new this(...args, {
@@ -105,7 +119,8 @@ var SerializableError = class _SerializableError extends Error {
105
119
  wrappedError.details = [
106
120
  ...new Set(combinedDetails)
107
121
  ];
108
- wrappedError.message = `${wrappedError.message} > ${error?.message ?? String(error)}`;
122
+ const originalMessage = error?.message ?? String(error);
123
+ wrappedError.message = wrappedError.message ? `${wrappedError.message} > ${originalMessage}` : originalMessage;
109
124
  return wrappedError;
110
125
  }
111
126
  };
@@ -117,7 +132,7 @@ var NonRetryableError = class extends SerializableError {
117
132
  super(message, options);
118
133
  }
119
134
  };
120
- var AssertionError = class extends NonRetryableError {
135
+ var AssertionError = class extends SerializableError {
121
136
  static {
122
137
  __name(this, "AssertionError");
123
138
  }
@@ -125,7 +140,7 @@ var AssertionError = class extends NonRetryableError {
125
140
  super(message, options);
126
141
  }
127
142
  };
128
- var ActivityNotAvailableError = class extends NonRetryableError {
143
+ var ActivityNotAvailableError = class extends SerializableError {
129
144
  static {
130
145
  __name(this, "ActivityNotAvailableError");
131
146
  }
@@ -191,5 +206,5 @@ var assertUnreachable = /* @__PURE__ */ __name((value) => {
191
206
  }, "assertUnreachable");
192
207
 
193
208
  export { ActivityNotAvailableError, AssertionError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError };
194
- //# sourceMappingURL=OKCSPRBL.js.map
195
- //# sourceMappingURL=OKCSPRBL.js.map
209
+ //# sourceMappingURL=ZAAFJP3A.js.map
210
+ //# sourceMappingURL=ZAAFJP3A.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","nonRetryable","args","NonRetryableError","wrap","wrappedError","combinedDetails","Set","originalMessage","String","AssertionError","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,EAAOJ,OAAAA;EAC9B,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,SAAA;AACX,EAAA;AACJ,CAAA,EAVuC,gCAAA,CAAA;AAYhC,SAASK,qBAAqBP,GAAAA,EAA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LvC;;;AAsLI,EAAA,WAAA,CAAYf,SAAiBmB,OAAAA,EAAwB;AACjD,IAAA,KAAA,CAAMnB,SAASmB,OAAAA,CAAAA;AACf,IAAA,IAAA,CAAKT,IAAAA,GAAO,mBAAA;AAChB,EAAA;AACJ;AAEO,IAAMuC,oBAAAA,GAAN,cAAmClC,iBAAAA,CAAAA;EA5L1C;;;AA6LI,EAAA,WAAA,CAAYI,OAAAA,EAAwB;AAChC,IAAA,KAAA,CAAM,mCAAmCA,OAAAA,CAAAA;AAC7C,EAAA;AACJ;AAEO,IAAM+B,UAAAA,GAAN,cAAyBlC,KAAAA,CAAAA;EAlMhC;;;;AAmMI,EAAA,WAAA,CAA4BmC,IAAAA,EAAa;AACrC,IAAA,KAAA,CAAMA,IAAAA,CAAKC,GAAAA,CAAI,CAACtD,GAAAA,KAAQA,GAAAA,CAAIE,OAAO,CAAA,CAAEqD,IAAAA,CAAK,IAAA,CAAA,CAAA,EAAA,IAAA,CADlBF,IAAAA,GAAAA,IAAAA;AAE5B,EAAA;AACJ;AAYO,IAAMG,UAAAA,mBAAa,MAAA,CAAA,CACtBtD,OAAAA,EACAI,KAAAA,KAAAA;AAEA,EAAA,MAAMA,KAAAA,GAAQJ,OAAAA,CAAAA,IAAY,IAAIgB,MAAMhB,OAAAA,CAAAA;AACxC,CAAA,EAL0B,YAAA;AAWnB,IAAMuD,iBAAAA,2BAAqBC,KAAAA,KAAAA;AAC9B,EAAA,MAAM,IAAIxB,iBAAAA,CAAkB,CAAA,mBAAA,EAAsBwB,KAAAA,CAAAA,CAAO,CAAA;AAC7D,CAAA,EAFiC,mBAAA","file":"ZAAFJP3A.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 /*\n * Constructs this error and marks it non-retryable, e.g. AssertionError.nonRetryable('...').\n * Being non-retryable is a modifier rather than a kind of error, so prefer this over extending\n * NonRetryableError. Retry policies match on the exact class name and not the prototype chain,\n * so a subclass is silently retried unless its own name is registered in every policy.\n * The result keeps this error's class chain in details, so inStackOf still narrows to it.\n */\n static nonRetryable<T extends new (...args: any) => SerializableError>(\n this: T,\n ...args: ConstructorParameters<T>\n ): NonRetryableError {\n const error = new this(...args);\n // exact match only, since a subclass of NonRetryableError still reports its own name\n if (error.constructor === NonRetryableError) {\n return error as NonRetryableError;\n }\n\n return NonRetryableError.wrap(error, '');\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 const originalMessage = error?.message ?? String(error);\n wrappedError.message = wrappedError.message\n ? `${wrappedError.message} > ${originalMessage}`\n : originalMessage;\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\n/**\n * Thrown when an internal invariant is violated.\n * Throw it via AssertionError.nonRetryable(...); plain construction is retryable.\n */\nexport class AssertionError extends SerializableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\n/**\n * Thrown when an activity method or chain capability is not available.\n * Prefer this over plain Error for unimplemented stubs and missing chain implementations.\n * Throw it via ActivityNotAvailableError.nonRetryable(...); plain construction is retryable.\n */\nexport class ActivityNotAvailableError 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\n/**\n * Throw from an expression position (`??`, `||`, ternaries, `return`, etc.).\n *\n * Prefer a normal `throw new Error(...)` / `throw new SomeError(...)` in statement\n * position.\n *\n * @example\n * const value = maybe ?? throwError('missing value');\n * const value = maybe ?? throwError('missing value', (msg) => new NonRetryableError(msg));\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.d.ts CHANGED
@@ -21,21 +21,25 @@ export declare abstract class SerializableError extends Error {
21
21
  constructor(message: string, options?: ErrorOptions);
22
22
  private static computeClassChain;
23
23
  static inStackOf<T extends abstract new (...args: any) => any>(this: T, error: any): SerializableError | undefined;
24
+ static nonRetryable<T extends new (...args: any) => SerializableError>(this: T, ...args: ConstructorParameters<T>): NonRetryableError;
24
25
  static wrap<T extends new (...args: any) => SerializableError>(this: T, error: any, ...args: RemoveErrorOptions<ConstructorParameters<T>>): InstanceType<T>;
25
26
  }
26
27
  export declare class NonRetryableError extends SerializableError {
27
28
  constructor(message: string, options?: ErrorOptions);
28
29
  }
29
- /** Thrown when an internal invariant is violated. */
30
- export declare class AssertionError extends NonRetryableError {
30
+ /**
31
+ * Thrown when an internal invariant is violated.
32
+ * Throw it via AssertionError.nonRetryable(...); plain construction is retryable.
33
+ */
34
+ export declare class AssertionError extends SerializableError {
31
35
  constructor(message: string, options?: ErrorOptions);
32
36
  }
33
37
  /**
34
38
  * Thrown when an activity method or chain capability is not available.
35
- * Extends NonRetryableError so activity registries treat the failure as non-retryable.
36
39
  * Prefer this over plain Error for unimplemented stubs and missing chain implementations.
40
+ * Throw it via ActivityNotAvailableError.nonRetryable(...); plain construction is retryable.
37
41
  */
38
- export declare class ActivityNotAvailableError extends NonRetryableError {
42
+ export declare class ActivityNotAvailableError extends SerializableError {
39
43
  constructor(message: string, options?: ErrorOptions);
40
44
  }
41
45
  export declare class NotFoundError extends SerializableError {
@@ -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,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE7F;;;;;GAKG;AACH,8BAAsB,iBAAkB,SAAQ,KAAK;IACjD,OAAO,EAAE,MAAM,EAAE,CAAC;IAMlB,KAAK,EAAE,OAAO,CAAC;gBACH,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAQnD,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAqBhC,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,K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CAAC,CAAC,CAAC,CAAC,GACtD,YAAY,CAAC,CAAC,CAAC;CAerB;AAED,qBAAa,iBAAkB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGtD;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,iBAAiB;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGtD;AAED;;;;GAIG;AACH,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;;;;;;;;;GASG;AACH,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 { ActivityNotAvailableError, AssertionError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './OKCSPRBL.js';
1
+ export { ActivityNotAvailableError, AssertionError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './ZAAFJP3A.js';
2
2
  import './VUOMXK5T.js';
3
3
  //# sourceMappingURL=errors.js.map
4
4
  //# sourceMappingURL=errors.js.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { ActivityNotAvailableError, AssertionError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './OKCSPRBL.js';
1
+ export { ActivityNotAvailableError, AssertionError, MultiError, NonEmittableError, NonRetryableError, NotFoundError, ProviderError, QuorumNotAchievedYet, SerializableError, assertUnreachable, convertErrorToObject, normalizeError, throwError } from './ZAAFJP3A.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": "1.2.45",
3
+ "version": "1.2.47",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,8 +23,8 @@
23
23
  "@types/ms": "^2.1.0",
24
24
  "tsup": "^8.4.0",
25
25
  "vitest": "^4.1.10",
26
- "@layerzerolabs/tsup-configuration": "1.2.45",
27
- "@layerzerolabs/typescript-configuration": "1.2.45"
26
+ "@layerzerolabs/tsup-configuration": "1.2.47",
27
+ "@layerzerolabs/typescript-configuration": "1.2.47"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public",
@@ -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","computeClassChain","instance","chain","proto","getPrototypeOf","prototype","push","inStackOf","includes","undefined","wrap","args","wrappedError","combinedDetails","Set","String","NonRetryableError","AssertionError","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,EAAOJ,OAAAA;EAC9B,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,SAAA;AACX,EAAA;AACJ,CAAA,EAVuC,gCAAA,CAAA;AAYhC,SAASK,qBAAqBP,GAAAA,EAAQ;AACzC,EAAA,OAAOI,IAAAA,CAAKC,MAAMD,IAAAA,CAAKI,SAAAA,CAAUR,KAAKS,MAAAA,CAAOC,mBAAAA,CAAoBV,GAAAA,CAAAA,CAAAA,CAAAA;AACrE;AAFgBO,MAAAA,CAAAA,oBAAAA,EAAAA,sBAAAA,CAAAA;AAIT,SAASI,eAAeX,GAAAA,EAAQ;AACnC,EAAA,MAAMM,KAAAA,GAAQC,qBAAqBP,GAAAA,CAAAA;AACnC,EAAA,OAAO;;AAEH,IAAA,GAAIM,MAAMM,IAAAA,GAAO;AAAEA,MAAAA,IAAAA,EAAMN,KAAAA,CAAMM;AAAK,KAAA,GAAI,EAAC;AACzC,IAAA,GAAIN,MAAMJ,OAAAA,GAAU;AAAEA,MAAAA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9B,EAAA,MAAM,IAAIlB,iBAAAA,CAAkB,CAAA,mBAAA,EAAsBkB,KAAAA,CAAAA,CAAO,CAAA;AAC7D,CAAA,EAFiC,mBAAA","file":"OKCSPRBL.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\n/** Thrown when an internal invariant is violated. */\nexport class AssertionError extends NonRetryableError {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\n/**\n * Thrown when an activity method or chain capability is not available.\n * Extends NonRetryableError so activity registries treat the failure as non-retryable.\n * Prefer this over plain Error for unimplemented stubs and missing chain implementations.\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\n/**\n * Throw from an expression position (`??`, `||`, ternaries, `return`, etc.).\n *\n * Prefer a normal `throw new Error(...)` / `throw new SomeError(...)` in statement\n * position.\n *\n * @example\n * const value = maybe ?? throwError('missing value');\n * const value = maybe ?? throwError('missing value', (msg) => new NonRetryableError(msg));\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"]}