@oliversalzburg/js-utils 0.0.59-dev.1 → 0.0.59-dev.3
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/errors/error-serializer.d.ts +9 -0
- package/errors/error-serializer.js +10 -0
- package/errors/error-serializer.js.map +1 -1
- package/errors/stream.d.ts +8 -0
- package/errors/stream.js +16 -0
- package/errors/stream.js.map +1 -0
- package/errors/tools.d.ts +11 -0
- package/errors/tools.js +14 -0
- package/errors/tools.js.map +1 -0
- package/package.json +1 -1
|
@@ -21,6 +21,15 @@ export declare const isError: (subject: unknown) => subject is Error;
|
|
|
21
21
|
* @group Errors
|
|
22
22
|
*/
|
|
23
23
|
export declare const unknownToError: (subject: unknown) => AbstractError;
|
|
24
|
+
/**
|
|
25
|
+
* Serializes an error into a string.
|
|
26
|
+
* @param error - The error to stringify.
|
|
27
|
+
* @returns A string representing the error.
|
|
28
|
+
* @group Errors
|
|
29
|
+
*/
|
|
30
|
+
export declare const errorToString: (error: Error & {
|
|
31
|
+
toString?: () => string;
|
|
32
|
+
}) => string;
|
|
24
33
|
/**
|
|
25
34
|
* Serializes an error into a JSON string.
|
|
26
35
|
* @param error - The error to stringify.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNil } from "../data/nil.js";
|
|
1
2
|
import { AbstractError } from "./AbstractError.js";
|
|
2
3
|
import { InternalError } from "./InternalError.js";
|
|
3
4
|
import { UnknownError } from "./UnknownError.js";
|
|
@@ -27,6 +28,15 @@ export const unknownToError = (subject) => {
|
|
|
27
28
|
}
|
|
28
29
|
return new UnknownError(String(subject));
|
|
29
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Serializes an error into a string.
|
|
33
|
+
* @param error - The error to stringify.
|
|
34
|
+
* @returns A string representing the error.
|
|
35
|
+
* @group Errors
|
|
36
|
+
*/
|
|
37
|
+
export const errorToString = (error) => {
|
|
38
|
+
return isNil(error.toString) ? Object.prototype.toString.call(error) : error.toString();
|
|
39
|
+
};
|
|
30
40
|
/**
|
|
31
41
|
* Serializes an error into a JSON string.
|
|
32
42
|
* @param error - The error to stringify.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-serializer.js","sourceRoot":"","sources":["../../source/errors/error-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASjD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAoB,EAAE;IAC5D,OAAO,OAAO,YAAY,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,gBAAgB,CAAC;AAClG,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAgB,EAAiB,EAAE;IAChE,IAAI,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACrB,OAAO,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAY,EAAU,EAAE;IAClD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAY,EAA2B,EAAE;IACrE,MAAM,MAAM,GAA4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;AACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a function that will receive errors (or anything else that was `throw`n)
|
|
3
|
+
* and prints it to a {@linkcode NodeJS.WriteStream}.
|
|
4
|
+
* @param stream - The stream to print errors to.
|
|
5
|
+
* @returns A function that will print errors to the stream.
|
|
6
|
+
* @group Errors
|
|
7
|
+
*/
|
|
8
|
+
export declare const redirectErrorsToStream: (stream: NodeJS.WriteStream) => ((error: unknown) => void);
|
package/errors/stream.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { errorToString, unknownToError } from "./error-serializer.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a function that will receive errors (or anything else that was `throw`n)
|
|
4
|
+
* and prints it to a {@linkcode NodeJS.WriteStream}.
|
|
5
|
+
* @param stream - The stream to print errors to.
|
|
6
|
+
* @returns A function that will print errors to the stream.
|
|
7
|
+
* @group Errors
|
|
8
|
+
*/
|
|
9
|
+
export const redirectErrorsToStream = (stream) => {
|
|
10
|
+
const printErrorsToStream = (unknownError) => {
|
|
11
|
+
const error = unknownToError(unknownError);
|
|
12
|
+
stream.write(errorToString(error) + "\n");
|
|
13
|
+
};
|
|
14
|
+
return printErrorsToStream;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../source/errors/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,MAA0B,EAA8B,EAAE;IAC/F,MAAM,mBAAmB,GAAG,CAAC,YAAqB,EAAQ,EAAE;QAC1D,MAAM,KAAK,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC;IACF,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General error-related tooling that fits no other module.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Throws the provided error.
|
|
7
|
+
* @param error - The error that will be thrown.
|
|
8
|
+
* @throws The provided error.
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare const rethrow: (error: unknown) => never;
|
package/errors/tools.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General error-related tooling that fits no other module.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Throws the provided error.
|
|
7
|
+
* @param error - The error that will be thrown.
|
|
8
|
+
* @throws The provided error.
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export const rethrow = (error) => {
|
|
12
|
+
throw error;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../source/errors/tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,EAAE;IACxC,MAAM,KAAK,CAAC;AACd,CAAC,CAAC"}
|
package/package.json
CHANGED