@owlmeans/error 0.1.18-rc.8 → 0.1.18
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/README.md +228 -39
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/error/SKILL.md +47 -5
- package/build/consts.d.ts +13 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +13 -0
- package/build/consts.js.map +1 -1
- package/build/errors.d.ts +33 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +146 -0
- package/build/errors.js.map +1 -0
- package/build/helper/types.d.ts +9 -0
- package/build/helper/types.d.ts.map +1 -0
- package/build/helper/types.js +2 -0
- package/build/helper/types.js.map +1 -0
- package/build/helper.d.ts +3 -3
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +7 -3
- package/build/helper.js.map +1 -1
- package/build/i18n/fr.json +4 -0
- package/build/i18n.js +10 -8
- package/build/i18n.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/resilient.d.ts.map +1 -1
- package/build/resilient.js.map +1 -1
- package/build/types.d.ts +7 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +7 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/utils.d.ts +0 -2
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +21 -17
- package/build/utils.js.map +1 -1
- package/package.json +4 -3
- package/src/consts.ts +16 -0
- package/src/errors.ts +177 -0
- package/src/helper/types.ts +9 -0
- package/src/helper.ts +12 -5
- package/src/i18n/fr.json +4 -0
- package/src/i18n.ts +10 -8
- package/src/index.ts +2 -1
- package/src/types.local.ts +7 -0
- package/src/types.ts +8 -1
- package/src/utils.ts +23 -21
- package/tests/copies.spec.ts +138 -0
- package/tests/tsconfig.json +17 -0
- package/tsconfig.json +1 -1
- package/src/resilient.ts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AED,OAAO,CAAC,IAA0B;QAChC,OAAO,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;IAED,iBAAiB,KAAW,CAAC;CAC9B;AAED,oGAAoG;AACpG,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,SAAS,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AAEjF,8FAA8F;AAC9F,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAE,SAAiD,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;IACnI,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC3C,GAAG,oBAAoB,CAAC,cAA2C,CAAC;QACpE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;KAClB,EAAE,EAAE,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ResilientError } from '../errors.js';
|
|
2
|
+
/** Boundary shortcuts over `ResilientError.ensure` and `ResilientError.marshal`. */
|
|
3
|
+
export interface ErrorHelper {
|
|
4
|
+
/** `ResilientError.ensure`, typed to the subclass the caller expects. */
|
|
5
|
+
enuserError: <T extends ResilientError = ResilientError>(err: Error | string, throwOnUnknown?: boolean) => T;
|
|
6
|
+
/** `ensure` then `marshal`, for a boundary that only carries an `Error` or a string. */
|
|
7
|
+
marshalError: (err: Error | string) => Error;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/helper/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD,oFAAoF;AACpF,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,WAAW,EAAE,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,KAAK,CAAC,CAAA;IAC5G,wFAAwF;IACxF,YAAY,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,KAAK,KAAK,CAAA;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/helper/types.ts"],"names":[],"mappings":""}
|
package/build/helper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
1
|
+
import type { ErrorHelper } from './helper/types.js';
|
|
2
|
+
export declare const createErrorHelper: () => ErrorHelper;
|
|
3
|
+
export declare const errorHelper: ErrorHelper;
|
|
4
4
|
//# sourceMappingURL=helper.d.ts.map
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,eAAO,MAAM,iBAAiB,QAAO,WAQpC,CAAA;AAED,eAAO,MAAM,WAAW,aAAsB,CAAA"}
|
package/build/helper.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { ResilientError } from './
|
|
2
|
-
export const
|
|
3
|
-
|
|
1
|
+
import { ResilientError } from './errors.js';
|
|
2
|
+
export const createErrorHelper = () => {
|
|
3
|
+
const enuserError = (err, throwOnUnknown) => ResilientError.ensure(err, throwOnUnknown);
|
|
4
|
+
const marshalError = (err) => ResilientError.marshal(ResilientError.ensure(err));
|
|
5
|
+
return { enuserError, marshalError };
|
|
6
|
+
};
|
|
7
|
+
export const errorHelper = createErrorHelper();
|
|
4
8
|
//# sourceMappingURL=helper.js.map
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAG5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAgB,EAAE;IACjD,MAAM,WAAW,GAAG,CAA4C,GAAmB,EAAE,cAAwB,EAAK,EAAE,CAClH,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAM,CAAA;IAEjD,MAAM,YAAY,GAAG,CAAC,GAAmB,EAAS,EAAE,CAClD,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IAEpD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,EAAE,CAAA"}
|
package/build/i18n.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i18nHelper } from '@owlmeans/i18n';
|
|
2
2
|
import en from './i18n/en.json' with { type: 'json' };
|
|
3
3
|
import pl from './i18n/pl.json' with { type: 'json' };
|
|
4
4
|
import ru from './i18n/ru.json' with { type: 'json' };
|
|
@@ -6,11 +6,13 @@ import be from './i18n/be.json' with { type: 'json' };
|
|
|
6
6
|
import uk from './i18n/uk.json' with { type: 'json' };
|
|
7
7
|
import es from './i18n/es.json' with { type: 'json' };
|
|
8
8
|
import de from './i18n/de.json' with { type: 'json' };
|
|
9
|
-
|
|
10
|
-
addI18nLib('
|
|
11
|
-
addI18nLib('
|
|
12
|
-
addI18nLib('
|
|
13
|
-
addI18nLib('
|
|
14
|
-
addI18nLib('
|
|
15
|
-
addI18nLib('
|
|
9
|
+
import fr from './i18n/fr.json' with { type: 'json' };
|
|
10
|
+
i18nHelper.addI18nLib('en', 'errors', en);
|
|
11
|
+
i18nHelper.addI18nLib('pl', 'errors', pl);
|
|
12
|
+
i18nHelper.addI18nLib('ru', 'errors', ru);
|
|
13
|
+
i18nHelper.addI18nLib('be', 'errors', be);
|
|
14
|
+
i18nHelper.addI18nLib('uk', 'errors', uk);
|
|
15
|
+
i18nHelper.addI18nLib('es', 'errors', es);
|
|
16
|
+
i18nHelper.addI18nLib('de', 'errors', de);
|
|
17
|
+
i18nHelper.addI18nLib('fr', 'errors', fr);
|
|
16
18
|
//# sourceMappingURL=i18n.js.map
|
package/build/i18n.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACrD,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACrD,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACrD,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACrD,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACrD,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AACrD,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAErD,UAAU,CAAC,IAAI,EAAE,QAAQ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AAQ,EAAE,EAAE,CAAC,CAAA;AACzC,UAAU,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAA"}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,mBAAmB,mBAAmB,CAAA;AACtC,cAAc,WAAW,CAAA"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAE1B,cAAc,WAAW,CAAA"}
|
package/build/resilient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resilient.d.ts","sourceRoot":"","sources":["../src/resilient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAGtE,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAc,SAAS,EAAE,MAAM,CAAY;IAE3C,OAAc,QAAQ,EAAE,MAAM,CAAiB;IAE/C,OAAc,UAAU,EAAE,SAAS,EAAE,CAAK;
|
|
1
|
+
{"version":3,"file":"resilient.d.ts","sourceRoot":"","sources":["../src/resilient.ts"],"names":[],"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;QAC9B,IAAI,GAAG,YAAY,cAAc,EAAE,CAAC;YAClC,OAAO,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;QACpF,CAAC;QAED,OAAO,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;IAChF,CAAC;IAEM,IAAI,GAAW,cAAc,CAAA;IAE7B,cAAc,CAAS;IAE9B,YAAY,IAAY,EAAE,OAAe,EAAE,KAAc;QACvD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,IAAI,CAAC,cAAc,GAAG,KAAK,CAAA;QAC7B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAA;QAClC,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,iBAAiB,KAAW,CAAC;;AAG/B,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC;IAC7B,GAAG,oBAAoB,CAAC,cAA2C,CAAC;IACpE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;CAClB,CAAC,CAAA"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type { ResilientError } from './
|
|
1
|
+
import type { ResilientError } from './errors.js';
|
|
2
2
|
export type ValueOrError<T> = T | ResilientError;
|
|
3
|
+
export interface MarshalErrorOptions {
|
|
4
|
+
/** Defaults to true for backwards compatibility outside an HTTP boundary. */
|
|
5
|
+
includeStack?: boolean;
|
|
6
|
+
/** Opaque correlation value appended as the fourth wire field. */
|
|
7
|
+
incidentId?: string;
|
|
8
|
+
}
|
|
3
9
|
export interface Converter {
|
|
4
10
|
match: (err: Error) => boolean;
|
|
5
11
|
convert: (err: Error) => ResilientError;
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,cAAc,CAAA;AAEhD,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAA;IAC9B,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,cAAc,CAAA;IACvC,WAAW,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAA;IACpC,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,cAAc,CAAA;CAC1C;AAED,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc;IAClF,KAAK,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;IACtD,KAAK,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;IACxC,QAAQ,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CONVERTER_REGISTRY } from './consts.js';
|
|
2
|
+
import type { Converter } from './types.js';
|
|
3
|
+
/** The slot of the process-wide converter registry on `globalThis`. */
|
|
4
|
+
export interface ConverterHolder {
|
|
5
|
+
[CONVERTER_REGISTRY]?: Converter[];
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=types.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,CAAC,kBAAkB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAA;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
|
package/build/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ResilientError } from './resilient.js';
|
|
2
1
|
import type { Converter, ResilientErrorConstructor } from './types.js';
|
|
3
2
|
export declare const createErrorConverter: (resilientErrorClass: ResilientErrorConstructor, errorClass?: ErrorConstructor) => Converter;
|
|
4
|
-
export declare const unmarshal: <T extends ResilientError = ResilientError>(errorClass: ResilientErrorConstructor) => (err: Error) => T;
|
|
5
3
|
//# sourceMappingURL=utils.d.ts.map
|
package/build/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAwBtE,eAAO,MAAM,oBAAoB,wBACV,yBAAyB,eACjC,gBAAgB,KAC5B,SAQF,CAAA"}
|
package/build/utils.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import { ResilientError } from './
|
|
2
|
-
|
|
3
|
-
return {
|
|
4
|
-
match: err => errorClass != null && err instanceof errorClass,
|
|
5
|
-
convert: err => new resilientErrorClass(err.message, err.stack),
|
|
6
|
-
isMarshaled: err => err.message.startsWith(resilientErrorClass.typeName + ResilientError.separator),
|
|
7
|
-
unmarshal: unmarshal(resilientErrorClass)
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export const unmarshal = (errorClass) => (err) => {
|
|
1
|
+
import { ResilientError } from './errors.js';
|
|
2
|
+
const unmarshal = (errorClass) => (err) => {
|
|
11
3
|
if (err instanceof errorClass) {
|
|
12
4
|
return err;
|
|
13
5
|
}
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
6
|
+
const fields = err.message.split(ResilientError.separator, 4);
|
|
7
|
+
if (fields.length < 2) {
|
|
16
8
|
throw SyntaxError('Invalid marshaled error');
|
|
17
9
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const error =
|
|
22
|
-
|
|
10
|
+
const [type, message, stack, incidentId] = fields;
|
|
11
|
+
// The base constructor takes (type, message, stack); subclasses take (message, stack).
|
|
12
|
+
// Keeping the base's wire type in place avoids shifting a plain Error's message into `type`.
|
|
13
|
+
const error = errorClass === ResilientError
|
|
14
|
+
? new errorClass(type, message, stack)
|
|
15
|
+
: new errorClass(message, stack);
|
|
16
|
+
error.type = type;
|
|
17
|
+
error.message = message;
|
|
18
|
+
error.incidentId = incidentId;
|
|
23
19
|
error.finalizeUnmarshal();
|
|
24
20
|
return error;
|
|
25
21
|
};
|
|
22
|
+
export const createErrorConverter = (resilientErrorClass, errorClass) => {
|
|
23
|
+
return {
|
|
24
|
+
match: err => errorClass != null && err instanceof errorClass,
|
|
25
|
+
convert: err => new resilientErrorClass(err.message, err.stack),
|
|
26
|
+
isMarshaled: err => err.message.startsWith(resilientErrorClass.typeName + ResilientError.separator),
|
|
27
|
+
unmarshal: unmarshal(resilientErrorClass)
|
|
28
|
+
};
|
|
29
|
+
};
|
|
26
30
|
//# sourceMappingURL=utils.js.map
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAG5C,MAAM,SAAS,GAAG,CAA4C,UAAqC,EAAE,EAAE,CACrG,CAAC,GAAU,EAAK,EAAE;IAChB,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC9B,OAAO,GAAQ,CAAA;IACjB,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;IAC7D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,WAAW,CAAC,yBAAyB,CAAC,CAAA;IAC9C,CAAC;IACD,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,GAAG,MAAM,CAAA;IACjD,uFAAuF;IACvF,6FAA6F;IAC7F,MAAM,KAAK,GAAG,UAAU,KAAK,cAAc;QACzC,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC;QACtC,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAClC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,KAAK,CAAC,OAAO,GAAG,OAAO,CAAA;IACvB,KAAK,CAAC,UAAU,GAAG,UAAU,CAAA;IAC7B,KAAK,CAAC,iBAAiB,EAAE,CAAA;IACzB,OAAO,KAAU,CAAA;AACnB,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,mBAA8C,EAC9C,UAA6B,EAClB,EAAE;IACb,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,UAAU,IAAI,IAAI,IAAI,GAAG,YAAY,UAAU;QAC7D,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,mBAAmB,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC;QAC/D,WAAW,EAAE,GAAG,CAAC,EAAE,CACjB,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,mBAAmB,CAAC,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC;QACjF,SAAS,EAAE,SAAS,CAAC,mBAAmB,CAAC;KAC1C,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/error",
|
|
3
|
-
"version": "0.1.18
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc -b",
|
|
8
|
+
"test": "bun test ./tests",
|
|
8
9
|
"dev": "sleep 156 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
|
|
9
10
|
"watch": "tsc -b -w --preserveWatchOutput --pretty"
|
|
10
11
|
},
|
|
@@ -21,10 +22,10 @@
|
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@owlmeans/i18n": "^0.1.18
|
|
25
|
+
"@owlmeans/i18n": "^0.1.18"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@owlmeans/dep-config": "
|
|
28
|
+
"@owlmeans/dep-config": "^0.1.18",
|
|
28
29
|
"nodemon": "^3.1.14",
|
|
29
30
|
"typescript": "^7.0.2"
|
|
30
31
|
},
|
package/src/consts.ts
CHANGED
|
@@ -2,3 +2,19 @@
|
|
|
2
2
|
export const SEPARATOR = '|||'
|
|
3
3
|
|
|
4
4
|
export const RESILENT_ERROR = 'ResilientError'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Marks every `ResilientError` instance, whichever copy of this module built it.
|
|
8
|
+
*
|
|
9
|
+
* A process can hold several copies of this package (`bun --preserve-symlinks` over a linked
|
|
10
|
+
* workspace resolves one package through several `node_modules` paths), and `instanceof` answers
|
|
11
|
+
* for one copy only. `Symbol.for` returns the same symbol in every copy, so the brand is the
|
|
12
|
+
* structural proof `ensure`, `marshal` and `instanceof` read.
|
|
13
|
+
*/
|
|
14
|
+
export const RESILIENT_BRAND: unique symbol = Symbol.for('@owlmeans/error:resilient')
|
|
15
|
+
|
|
16
|
+
/** The `globalThis` key of the converter registry every copy of this module shares. */
|
|
17
|
+
export const CONVERTER_REGISTRY: unique symbol = Symbol.for('@owlmeans/error:converters')
|
|
18
|
+
|
|
19
|
+
/** Marks the catch-all converter, so a second module copy does not push another one. */
|
|
20
|
+
export const CATCH_ALL_CONVERTER: unique symbol = Symbol.for('@owlmeans/error:catch-all')
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { CATCH_ALL_CONVERTER, CONVERTER_REGISTRY, RESILENT_ERROR, RESILIENT_BRAND, SEPARATOR } from './consts.js'
|
|
2
|
+
import type { Converter, MarshalErrorOptions, ResilientErrorConstructor } from './types.js'
|
|
3
|
+
import { createErrorConverter } from './utils.js'
|
|
4
|
+
import type { ConverterHolder } from './types.local.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one converter registry of the process.
|
|
8
|
+
*
|
|
9
|
+
* Kept on `globalThis` so every copy of this module registers into, and unmarshals from, the same
|
|
10
|
+
* list: a class registered by one copy is rebuilt by another. Registration order is kept across
|
|
11
|
+
* copies, so the last registration of a type name still wins.
|
|
12
|
+
*/
|
|
13
|
+
const sharedConverters = (): Converter[] => {
|
|
14
|
+
const holder = globalThis as ConverterHolder
|
|
15
|
+
holder[CONVERTER_REGISTRY] ??= []
|
|
16
|
+
|
|
17
|
+
return holder[CONVERTER_REGISTRY]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The type names a class declares itself and inherits, nearest first — only names a class owns.
|
|
22
|
+
*
|
|
23
|
+
* A class that does not redeclare `typeName` inherits its parent's value, and counting that twice
|
|
24
|
+
* would let a check against the subclass match any instance of the parent.
|
|
25
|
+
*/
|
|
26
|
+
const lineageOf = (ctor: unknown): string[] => {
|
|
27
|
+
const names: string[] = []
|
|
28
|
+
let current = ctor
|
|
29
|
+
while (typeof current === 'function') {
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(current, 'typeName')) {
|
|
31
|
+
const name = (current as { typeName?: unknown }).typeName
|
|
32
|
+
if (typeof name === 'string') {
|
|
33
|
+
names.push(name)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
current = Object.getPrototypeOf(current)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return names
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether a value is a `ResilientError` built by ANY copy of this module.
|
|
44
|
+
*
|
|
45
|
+
* Structural: the shared brand plus the `type` and `marshal` every instance carries.
|
|
46
|
+
*/
|
|
47
|
+
export const isResilientError = (value: unknown): value is ResilientError => {
|
|
48
|
+
if (value == null || typeof value !== 'object') {
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
const candidate = value as { [RESILIENT_BRAND]?: unknown, type?: unknown, marshal?: unknown }
|
|
52
|
+
|
|
53
|
+
return candidate[RESILIENT_BRAND] === true
|
|
54
|
+
&& typeof candidate.type === 'string'
|
|
55
|
+
&& typeof candidate.marshal === 'function'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class ResilientError extends Error {
|
|
59
|
+
public static separator: string = SEPARATOR
|
|
60
|
+
|
|
61
|
+
public static typeName: string = RESILENT_ERROR
|
|
62
|
+
|
|
63
|
+
public static converters: Converter[] = sharedConverters()
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* `instanceof` that holds across module copies.
|
|
67
|
+
*
|
|
68
|
+
* The native prototype check answers first. Failing that, a branded instance matches when its
|
|
69
|
+
* class lineage ENDS WITH this class's lineage — the same own type names, in the same order, up
|
|
70
|
+
* to the base. So `instanceof AuthFailedError` accepts an `AuthFailedError` (or a subclass of it)
|
|
71
|
+
* from another copy, and never a sibling class or a parent. A class that does not declare its
|
|
72
|
+
* own `typeName` cannot be told apart structurally and answers natively only.
|
|
73
|
+
*/
|
|
74
|
+
public static override [Symbol.hasInstance]<T extends abstract new (...args: any[]) => any>(
|
|
75
|
+
this: T, instance: unknown
|
|
76
|
+
): instance is InstanceType<T> {
|
|
77
|
+
if (Function.prototype[Symbol.hasInstance].call(this, instance)) {
|
|
78
|
+
return true
|
|
79
|
+
}
|
|
80
|
+
if (!isResilientError(instance) || !Object.prototype.hasOwnProperty.call(this, 'typeName')) {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
const expected = lineageOf(this)
|
|
84
|
+
const actual = lineageOf(Object.getPrototypeOf(instance)?.constructor)
|
|
85
|
+
const offset = actual.length - expected.length
|
|
86
|
+
|
|
87
|
+
return offset >= 0 && expected.every((name, index) => actual[offset + index] === name)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public static registerErrorClass(resilientErrorClass: ResilientErrorConstructor, errorClass?: ErrorConstructor): Converter {
|
|
91
|
+
const converter = createErrorConverter(resilientErrorClass, errorClass)
|
|
92
|
+
this.converters.push(converter)
|
|
93
|
+
|
|
94
|
+
return converter
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public static ensure(err: Error | string, throwOnUnknown?: boolean): ResilientError {
|
|
98
|
+
err = typeof err === 'string' ? new Error(err) : err
|
|
99
|
+
if (isResilientError(err)) {
|
|
100
|
+
return err
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// We don't proceed SyntaxError - system should crash in this case
|
|
104
|
+
if (err instanceof SyntaxError) {
|
|
105
|
+
throw err
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Umarshal marhalled error that is wrapepd to ordinary error
|
|
109
|
+
const unmarhaller = this.converters.toReversed().find(converter => converter.isMarshaled(err))
|
|
110
|
+
if (unmarhaller != null) {
|
|
111
|
+
return unmarhaller.unmarshal(err)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Convert object of Error subtypes to ResilientError subtype
|
|
115
|
+
const converter = this.converters.find(converter => converter.match(err))
|
|
116
|
+
if (converter != null) {
|
|
117
|
+
return converter.convert(err)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (throwOnUnknown === true) {
|
|
121
|
+
throw err
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return new ResilientError(this.typeName, err.message, err.stack)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public static marshal(err: Error, opts?: MarshalErrorOptions): Error {
|
|
128
|
+
const resilient = isResilientError(err)
|
|
129
|
+
const structuralType = (err as Error & { type?: unknown }).type
|
|
130
|
+
const type = resilient
|
|
131
|
+
? err.type
|
|
132
|
+
: typeof structuralType === 'string' ? structuralType : this.typeName
|
|
133
|
+
const stack = opts?.includeStack === false
|
|
134
|
+
? ''
|
|
135
|
+
: resilient ? err.oiriginalStack : err.stack
|
|
136
|
+
const fields: Array<string | undefined> = [type, err.message, stack]
|
|
137
|
+
if (opts?.incidentId != null) {
|
|
138
|
+
fields.push(opts.incidentId)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return new Error(fields.join(this.separator))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public type: string = RESILENT_ERROR
|
|
145
|
+
|
|
146
|
+
public oiriginalStack?: string
|
|
147
|
+
|
|
148
|
+
/** Correlates a serialized boundary error with the server log entry that owns its full stack. */
|
|
149
|
+
public incidentId?: string
|
|
150
|
+
|
|
151
|
+
constructor(type: string, message: string, stack?: string) {
|
|
152
|
+
super(message)
|
|
153
|
+
this.type = type
|
|
154
|
+
if (stack != null) {
|
|
155
|
+
this.oiriginalStack = stack
|
|
156
|
+
} else {
|
|
157
|
+
this.oiriginalStack = this.stack
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
marshal(opts?: MarshalErrorOptions): Error {
|
|
162
|
+
return ResilientError.marshal(this, opts)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
finalizeUnmarshal(): void { }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// On the prototype, not the instance: non-enumerable, and inherited by every subclass of this copy.
|
|
169
|
+
Object.defineProperty(ResilientError.prototype, RESILIENT_BRAND, { value: true })
|
|
170
|
+
|
|
171
|
+
// One catch-all per process: a second module copy finds the first copy's entry and adds none.
|
|
172
|
+
if (!ResilientError.converters.some(converter => (converter as { [CATCH_ALL_CONVERTER]?: unknown })[CATCH_ALL_CONVERTER] === true)) {
|
|
173
|
+
ResilientError.converters.push(Object.assign({
|
|
174
|
+
...createErrorConverter(ResilientError as ResilientErrorConstructor),
|
|
175
|
+
match: () => true,
|
|
176
|
+
}, { [CATCH_ALL_CONVERTER]: true }))
|
|
177
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ResilientError } from '../errors.js'
|
|
2
|
+
|
|
3
|
+
/** Boundary shortcuts over `ResilientError.ensure` and `ResilientError.marshal`. */
|
|
4
|
+
export interface ErrorHelper {
|
|
5
|
+
/** `ResilientError.ensure`, typed to the subclass the caller expects. */
|
|
6
|
+
enuserError: <T extends ResilientError = ResilientError>(err: Error | string, throwOnUnknown?: boolean) => T
|
|
7
|
+
/** `ensure` then `marshal`, for a boundary that only carries an `Error` or a string. */
|
|
8
|
+
marshalError: (err: Error | string) => Error
|
|
9
|
+
}
|
package/src/helper.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { ResilientError } from './
|
|
1
|
+
import { ResilientError } from './errors.js'
|
|
2
|
+
import type { ErrorHelper } from './helper/types.js'
|
|
2
3
|
|
|
3
|
-
export const
|
|
4
|
-
ResilientError
|
|
4
|
+
export const createErrorHelper = (): ErrorHelper => {
|
|
5
|
+
const enuserError = <T extends ResilientError = ResilientError>(err: Error | string, throwOnUnknown?: boolean): T =>
|
|
6
|
+
ResilientError.ensure(err, throwOnUnknown) as T
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const marshalError = (err: Error | string): Error =>
|
|
9
|
+
ResilientError.marshal(ResilientError.ensure(err))
|
|
10
|
+
|
|
11
|
+
return { enuserError, marshalError }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const errorHelper = createErrorHelper()
|
package/src/i18n/fr.json
ADDED
package/src/i18n.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i18nHelper } from '@owlmeans/i18n'
|
|
2
2
|
|
|
3
3
|
import en from './i18n/en.json' with { type: 'json' }
|
|
4
4
|
import pl from './i18n/pl.json' with { type: 'json' }
|
|
@@ -7,11 +7,13 @@ import be from './i18n/be.json' with { type: 'json' }
|
|
|
7
7
|
import uk from './i18n/uk.json' with { type: 'json' }
|
|
8
8
|
import es from './i18n/es.json' with { type: 'json' }
|
|
9
9
|
import de from './i18n/de.json' with { type: 'json' }
|
|
10
|
+
import fr from './i18n/fr.json' with { type: 'json' }
|
|
10
11
|
|
|
11
|
-
addI18nLib('en', 'errors', en)
|
|
12
|
-
addI18nLib('pl', 'errors', pl)
|
|
13
|
-
addI18nLib('ru', 'errors', ru)
|
|
14
|
-
addI18nLib('be', 'errors', be)
|
|
15
|
-
addI18nLib('uk', 'errors', uk)
|
|
16
|
-
addI18nLib('es', 'errors', es)
|
|
17
|
-
addI18nLib('de', 'errors', de)
|
|
12
|
+
i18nHelper.addI18nLib('en', 'errors', en)
|
|
13
|
+
i18nHelper.addI18nLib('pl', 'errors', pl)
|
|
14
|
+
i18nHelper.addI18nLib('ru', 'errors', ru)
|
|
15
|
+
i18nHelper.addI18nLib('be', 'errors', be)
|
|
16
|
+
i18nHelper.addI18nLib('uk', 'errors', uk)
|
|
17
|
+
i18nHelper.addI18nLib('es', 'errors', es)
|
|
18
|
+
i18nHelper.addI18nLib('de', 'errors', de)
|
|
19
|
+
i18nHelper.addI18nLib('fr', 'errors', fr)
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import type { ResilientError } from './
|
|
1
|
+
import type { ResilientError } from './errors.js'
|
|
2
2
|
|
|
3
3
|
export type ValueOrError<T> = T | ResilientError
|
|
4
4
|
|
|
5
|
+
export interface MarshalErrorOptions {
|
|
6
|
+
/** Defaults to true for backwards compatibility outside an HTTP boundary. */
|
|
7
|
+
includeStack?: boolean
|
|
8
|
+
/** Opaque correlation value appended as the fourth wire field. */
|
|
9
|
+
incidentId?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
export interface Converter {
|
|
6
13
|
match: (err: Error) => boolean
|
|
7
14
|
convert: (err: Error) => ResilientError
|