@douglasneuroinformatics/libjs 3.1.1 → 3.2.0
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/exception.d.ts +6 -3
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +27 -27
- package/package.json +1 -1
package/dist/exception.d.ts
CHANGED
|
@@ -35,6 +35,11 @@ interface ExceptionLike extends Error, ExceptionOptions {
|
|
|
35
35
|
}
|
|
36
36
|
declare function parseStack(stack: string | undefined): string[];
|
|
37
37
|
declare function parseStack(error: Error): string[];
|
|
38
|
+
declare function formatError(error: Error & {
|
|
39
|
+
details?: {
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
}): string;
|
|
38
43
|
declare function errorToJSON(error: Error, { includeStack }?: {
|
|
39
44
|
includeStack?: boolean;
|
|
40
45
|
}): string;
|
|
@@ -46,8 +51,6 @@ declare abstract class BaseException<TParams extends ExceptionParams, TOptions e
|
|
|
46
51
|
toAsyncErr(): ResultAsync<never, this>;
|
|
47
52
|
toErr(): Result<never, this>;
|
|
48
53
|
toString(): string;
|
|
49
|
-
private extractCauses;
|
|
50
|
-
private formatError;
|
|
51
54
|
}
|
|
52
55
|
type CoreExceptionConstructor = ToAbstractConstructor<ExceptionConstructor<ExceptionParams, ExceptionOptions>>;
|
|
53
56
|
declare class ExceptionBuilder<TParams extends ExceptionParams | undefined, TOptions extends ExceptionOptions, TStaticMethods extends {
|
|
@@ -130,5 +133,5 @@ export declare const ValidationException: ExceptionType<{
|
|
|
130
133
|
[key: string]: unknown;
|
|
131
134
|
}>;
|
|
132
135
|
export type { ExceptionConstructor, ExceptionConstructorArgs, ExceptionLike, ExceptionName, ExceptionOptions, ExceptionParams, ExceptionStatic, ExceptionType };
|
|
133
|
-
export { BaseException, errorToJSON, ExceptionBuilder, OutOfRangeException, parseStack, RuntimeException, serializeError, ValueException };
|
|
136
|
+
export { BaseException, errorToJSON, ExceptionBuilder, formatError, OutOfRangeException, parseStack, RuntimeException, serializeError, ValueException };
|
|
134
137
|
//# sourceMappingURL=exception.d.ts.map
|
package/dist/exception.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAMA,OAAO,EAAiB,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAe,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAKhC,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,aAAa,GAAG,GAAG,MAAM,WAAW,CAAC;AAE1C,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,KAAK,eAAe,CAAC,QAAQ,GAAG,GAAG,IAAI;IACrC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,GAAG,MAAM,CAAC;IACnD,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,KAAK,wBAAwB,CAAC,OAAO,SAAS,eAAe,EAAE,QAAQ,SAAS,gBAAgB,IAC9F,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,SAAS,IAAI,GAC1C,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,GACtC,OAAO,SAAS;IAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,MAAM,CAAA;CAAE,GAC9D,CAAC,QAAQ,CA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CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE;eAKlB,MAAM;;iBALxB,MAAM;iBAAO,MAAM;mBAAS,MAAM;;;;iBAAzC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE;;EAQ9D,CAAC;AAEX,eAAO,MAAQ,mBAAmB;;;;aACL;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAA;KAAE;;;EAEhE,CAAC;AAEX,YAAY,EACV,oBAAoB,EACpB,wBAAwB,EACxB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,EACd,CAAC;AAEF,OAAO,EACL,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,CAAC"}
|
package/dist/exception.js
CHANGED
|
@@ -12,6 +12,31 @@ function parseStack(errorOrStack) {
|
|
|
12
12
|
const stack = typeof errorOrStack === 'string' ? errorOrStack : errorOrStack?.stack;
|
|
13
13
|
return extractStack.lines(cleanStack(stack, { pretty: true }));
|
|
14
14
|
}
|
|
15
|
+
function formatSingleError(err) {
|
|
16
|
+
const result = [`${err.name}: ${err.message}`];
|
|
17
|
+
parseStack(err).forEach((line) => {
|
|
18
|
+
result.push(` at ${line}`);
|
|
19
|
+
});
|
|
20
|
+
if (err.details) {
|
|
21
|
+
result.push(indentLines(`details: ${stringifyObject(err.details, { indent: ' ' })}`, 4));
|
|
22
|
+
}
|
|
23
|
+
return result.join('\n');
|
|
24
|
+
}
|
|
25
|
+
function formatError(error) {
|
|
26
|
+
const causes = [];
|
|
27
|
+
let cause = error.cause;
|
|
28
|
+
while (cause instanceof Error) {
|
|
29
|
+
causes.push(cause);
|
|
30
|
+
cause = cause.cause;
|
|
31
|
+
}
|
|
32
|
+
const parts = [];
|
|
33
|
+
causes.toReversed().forEach((c) => {
|
|
34
|
+
parts.push(formatSingleError(c));
|
|
35
|
+
parts.push('\nThe above exception was the cause of the following exception:\n');
|
|
36
|
+
});
|
|
37
|
+
parts.push(formatSingleError(error));
|
|
38
|
+
return parts.join('\n');
|
|
39
|
+
}
|
|
15
40
|
function errorToJSON(error, { includeStack = true } = {}) {
|
|
16
41
|
const serialize = (error) => {
|
|
17
42
|
const { cause, stack, ...serialized } = serializeError(error);
|
|
@@ -41,32 +66,7 @@ class BaseException extends Error {
|
|
|
41
66
|
return err(this);
|
|
42
67
|
}
|
|
43
68
|
toString() {
|
|
44
|
-
|
|
45
|
-
this.extractCauses(this).forEach((error) => {
|
|
46
|
-
result.push(this.formatError(error));
|
|
47
|
-
result.push('\nThe above exception was the cause of the following exception:\n');
|
|
48
|
-
});
|
|
49
|
-
result.push(this.formatError(this));
|
|
50
|
-
return result.join('\n');
|
|
51
|
-
}
|
|
52
|
-
extractCauses(error) {
|
|
53
|
-
const errors = [];
|
|
54
|
-
let cause = error.cause;
|
|
55
|
-
while (cause instanceof Error) {
|
|
56
|
-
errors.push(cause);
|
|
57
|
-
cause = cause.cause;
|
|
58
|
-
}
|
|
59
|
-
return errors.toReversed();
|
|
60
|
-
}
|
|
61
|
-
formatError(error) {
|
|
62
|
-
const result = [`${error.name}: ${error.message}`];
|
|
63
|
-
parseStack(error).forEach((line) => {
|
|
64
|
-
result.push(` at ${line}`);
|
|
65
|
-
});
|
|
66
|
-
if (error.details) {
|
|
67
|
-
result.push(indentLines(`details: ${stringifyObject(error.details, { indent: ' ' })}`, 4));
|
|
68
|
-
}
|
|
69
|
-
return result.join('\n');
|
|
69
|
+
return formatError(this);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
class ExceptionBuilder {
|
|
@@ -135,4 +135,4 @@ export const { ValidationException } = new ExceptionBuilder()
|
|
|
135
135
|
.setOptionsType()
|
|
136
136
|
.setParams({ message: 'Zod schema validation failed', name: 'ValidationException' })
|
|
137
137
|
.build();
|
|
138
|
-
export { BaseException, errorToJSON, ExceptionBuilder, OutOfRangeException, parseStack, RuntimeException, serializeError, ValueException };
|
|
138
|
+
export { BaseException, errorToJSON, ExceptionBuilder, formatError, OutOfRangeException, parseStack, RuntimeException, serializeError, ValueException };
|
package/package.json
CHANGED