effect-errors 1.3.5 → 1.3.7
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 +4 -1
- package/capture-errors.d.ts +3 -2
- package/capture-errors.js +9 -3
- package/capture-errors.test.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -166,7 +166,8 @@ export interface CapturedErrors {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
export interface CaptureErrorsOptions {
|
|
169
|
-
reverseSpans
|
|
169
|
+
reverseSpans?: boolean;
|
|
170
|
+
stripCwd?: boolean;
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
type captureErrorsFunction: <E>(cause: Cause<E>, options: CaptureErrorsOptions) => CapturedErrors
|
|
@@ -189,6 +190,8 @@ await Effect.runPromise(
|
|
|
189
190
|
);
|
|
190
191
|
```
|
|
191
192
|
|
|
193
|
+

|
|
194
|
+
|
|
192
195
|
## ⚡ examples
|
|
193
196
|
|
|
194
197
|
I wrote some examples for fun and giggles. You can run them using:
|
package/capture-errors.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface CapturedErrors {
|
|
|
17
17
|
errors: ErrorData[];
|
|
18
18
|
}
|
|
19
19
|
export interface CaptureErrorsOptions {
|
|
20
|
-
reverseSpans
|
|
20
|
+
reverseSpans?: boolean;
|
|
21
|
+
stripCwd?: boolean;
|
|
21
22
|
}
|
|
22
|
-
export declare const captureErrors: <E>(cause: Cause<E>, { reverseSpans }?: CaptureErrorsOptions) => CapturedErrors;
|
|
23
|
+
export declare const captureErrors: <E>(cause: Cause<E>, { reverseSpans, stripCwd }?: CaptureErrorsOptions) => CapturedErrors;
|
package/capture-errors.js
CHANGED
|
@@ -4,10 +4,12 @@ exports.captureErrors = void 0;
|
|
|
4
4
|
var effect_1 = require("effect");
|
|
5
5
|
var Cause_1 = require("effect/Cause");
|
|
6
6
|
var capture_errors_from_cause_1 = require("./logic/errors/capture-errors-from-cause");
|
|
7
|
+
var strip_cwd_path_1 = require("./logic/strip-cwd-path");
|
|
7
8
|
var captureErrors = function (cause, _a) {
|
|
8
9
|
var _b = _a === void 0 ? {
|
|
9
10
|
reverseSpans: true,
|
|
10
|
-
|
|
11
|
+
stripCwd: true,
|
|
12
|
+
} : _a, reverseSpans = _b.reverseSpans, stripCwd = _b.stripCwd;
|
|
11
13
|
if ((0, Cause_1.isInterruptedOnly)(cause)) {
|
|
12
14
|
return {
|
|
13
15
|
interrupted: true,
|
|
@@ -15,7 +17,7 @@ var captureErrors = function (cause, _a) {
|
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
var errors = (0, capture_errors_from_cause_1.captureErrorsFrom)(cause).map(function (_a) {
|
|
18
|
-
var message = _a.message,
|
|
20
|
+
var message = _a.message, maybeStack = _a.stack, span = _a.span, errorType = _a.errorType, isPlainString = _a.isPlainString;
|
|
19
21
|
var spans = [];
|
|
20
22
|
if (span !== undefined) {
|
|
21
23
|
var current = span;
|
|
@@ -29,11 +31,15 @@ var captureErrors = function (cause, _a) {
|
|
|
29
31
|
current = effect_1.Option.getOrUndefined(current.parent);
|
|
30
32
|
}
|
|
31
33
|
}
|
|
34
|
+
var stack;
|
|
35
|
+
if (maybeStack !== undefined) {
|
|
36
|
+
stack = stripCwd === true ? (0, strip_cwd_path_1.stripCwdPath)(maybeStack) : maybeStack;
|
|
37
|
+
}
|
|
32
38
|
return {
|
|
33
39
|
errorType: errorType,
|
|
34
40
|
message: message,
|
|
35
41
|
stack: stack,
|
|
36
|
-
spans: reverseSpans ? spans.toReversed() : spans,
|
|
42
|
+
spans: reverseSpans === true ? spans.toReversed() : spans,
|
|
37
43
|
isPlainString: isPlainString,
|
|
38
44
|
};
|
|
39
45
|
});
|
package/capture-errors.test.js
CHANGED
|
@@ -53,7 +53,10 @@ void (0, console_mock_1.mockConsole)({
|
|
|
53
53
|
case 0: return [4 /*yield*/, (0, effect_cause_1.effectCause)(from_promise_1.fromPromiseTask)];
|
|
54
54
|
case 1:
|
|
55
55
|
cause = _b.sent();
|
|
56
|
-
result = (0, capture_errors_1.captureErrors)(cause, {
|
|
56
|
+
result = (0, capture_errors_1.captureErrors)(cause, {
|
|
57
|
+
reverseSpans: false,
|
|
58
|
+
stripCwd: false,
|
|
59
|
+
});
|
|
57
60
|
(0, vitest_1.expect)(result.interrupted).toBe(false);
|
|
58
61
|
(0, vitest_1.expect)(result.errors).toHaveLength(1);
|
|
59
62
|
_a = result.errors[0], errorType = _a.errorType, isPlainString = _a.isPlainString, message = _a.message, spans = _a.spans, stack = _a.stack;
|
|
@@ -83,7 +86,10 @@ void (0, console_mock_1.mockConsole)({
|
|
|
83
86
|
case 0: return [4 /*yield*/, (0, effect_cause_1.effectCause)(parallel_errors_1.withParallelErrorsTask)];
|
|
84
87
|
case 1:
|
|
85
88
|
cause = _u.sent();
|
|
86
|
-
result = (0, capture_errors_1.captureErrors)(cause, {
|
|
89
|
+
result = (0, capture_errors_1.captureErrors)(cause, {
|
|
90
|
+
reverseSpans: false,
|
|
91
|
+
stripCwd: false,
|
|
92
|
+
});
|
|
87
93
|
(0, vitest_1.expect)(result.interrupted).toBe(false);
|
|
88
94
|
(0, vitest_1.expect)(result.errors).toHaveLength(3);
|
|
89
95
|
firstError = result.errors[0];
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"repository": "https://github.com/jpb06/effect-errors.git",
|
|
3
3
|
"main": "index.js",
|
|
4
4
|
"name": "effect-errors",
|
|
5
|
-
"version": "1.3.
|
|
5
|
+
"version": "1.3.7",
|
|
6
6
|
"author": "jpb06 <jp.bois.06@outlook.fr>",
|
|
7
7
|
"description": "A POC for errors reporting in Effect",
|
|
8
8
|
"keywords": [],
|