effect-errors 1.3.1 → 1.3.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/README.md +11 -3
- package/capture-errors.d.ts +4 -1
- package/capture-errors.js +5 -2
- package/{caputre-errors.test.js → capture-errors.test.js} +2 -2
- package/examples/from-promise.js +5 -5
- package/package.json +11 -11
- package/pretty-print.d.ts +1 -1
- package/pretty-print.js +3 -3
- package/types/pretty-print-options.type.d.ts +2 -1
- package/types/pretty-print-options.type.js +2 -1
- /package/{caputre-errors.test.d.ts → capture-errors.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ So using it would look like this :
|
|
|
36
36
|
import { runPromise } from 'effect-errors';
|
|
37
37
|
|
|
38
38
|
await runPromise(
|
|
39
|
-
Effect.gen(function* (
|
|
39
|
+
Effect.gen(function* () {
|
|
40
40
|
// ...
|
|
41
41
|
}),
|
|
42
42
|
);
|
|
@@ -49,7 +49,7 @@ import { prettyPrint } from 'effect-errors';
|
|
|
49
49
|
|
|
50
50
|
await Effect.runPromise(
|
|
51
51
|
pipe(
|
|
52
|
-
Effect.gen(function* (
|
|
52
|
+
Effect.gen(function* () {
|
|
53
53
|
// ...
|
|
54
54
|
}),
|
|
55
55
|
Effect.sandbox,
|
|
@@ -78,6 +78,10 @@ const prettyPrint: <E>(cause: Cause<E>, options?: PrettyPrintOptions) => string;
|
|
|
78
78
|
|
|
79
79
|
> default: `false` (absolute paths)
|
|
80
80
|
|
|
81
|
+
#### `reverseSpans` - Whether spans order should reversed (entry point first instead of inner callee first)
|
|
82
|
+
|
|
83
|
+
> default: `true` (entry point first)
|
|
84
|
+
|
|
81
85
|
## ⚡ How should I raise errors?
|
|
82
86
|
|
|
83
87
|
The best way is to use either `SchemaError` or `TaggedError`.
|
|
@@ -161,7 +165,11 @@ export interface CapturedErrors {
|
|
|
161
165
|
errors: ErrorData[];
|
|
162
166
|
}
|
|
163
167
|
|
|
164
|
-
|
|
168
|
+
export interface CaptureErrorsOptions {
|
|
169
|
+
reverseSpans: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type captureErrorsFunction: <E>(cause: Cause<E>, options: CaptureErrorsOptions) => CapturedErrors
|
|
165
173
|
```
|
|
166
174
|
|
|
167
175
|
You can use `captureErrors` like so:
|
package/capture-errors.d.ts
CHANGED
|
@@ -16,4 +16,7 @@ export interface CapturedErrors {
|
|
|
16
16
|
interrupted: boolean;
|
|
17
17
|
errors: ErrorData[];
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export interface CaptureErrorsOptions {
|
|
20
|
+
reverseSpans: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const captureErrors: <E>(cause: Cause<E>, { reverseSpans }?: CaptureErrorsOptions) => CapturedErrors;
|
package/capture-errors.js
CHANGED
|
@@ -4,7 +4,10 @@ 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 captureErrors = function (cause) {
|
|
7
|
+
var captureErrors = function (cause, _a) {
|
|
8
|
+
var _b = _a === void 0 ? {
|
|
9
|
+
reverseSpans: true,
|
|
10
|
+
} : _a, reverseSpans = _b.reverseSpans;
|
|
8
11
|
if ((0, Cause_1.isInterruptedOnly)(cause)) {
|
|
9
12
|
return {
|
|
10
13
|
interrupted: true,
|
|
@@ -30,7 +33,7 @@ var captureErrors = function (cause) {
|
|
|
30
33
|
errorType: errorType,
|
|
31
34
|
message: message,
|
|
32
35
|
stack: stack,
|
|
33
|
-
spans: spans,
|
|
36
|
+
spans: reverseSpans ? spans.toReversed() : spans,
|
|
34
37
|
isPlainString: isPlainString,
|
|
35
38
|
};
|
|
36
39
|
});
|
|
@@ -53,7 +53,7 @@ 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, { reverseSpans: false });
|
|
57
57
|
(0, vitest_1.expect)(result.interrupted).toBe(false);
|
|
58
58
|
(0, vitest_1.expect)(result.errors).toHaveLength(1);
|
|
59
59
|
_a = result.errors[0], errorType = _a.errorType, isPlainString = _a.isPlainString, message = _a.message, spans = _a.spans, stack = _a.stack;
|
|
@@ -83,7 +83,7 @@ void (0, console_mock_1.mockConsole)({
|
|
|
83
83
|
case 0: return [4 /*yield*/, (0, effect_cause_1.effectCause)(parallel_errors_1.withParallelErrorsTask)];
|
|
84
84
|
case 1:
|
|
85
85
|
cause = _u.sent();
|
|
86
|
-
result = (0, capture_errors_1.captureErrors)(cause);
|
|
86
|
+
result = (0, capture_errors_1.captureErrors)(cause, { reverseSpans: false });
|
|
87
87
|
(0, vitest_1.expect)(result.interrupted).toBe(false);
|
|
88
88
|
(0, vitest_1.expect)(result.errors).toHaveLength(3);
|
|
89
89
|
firstError = result.errors[0];
|
package/examples/from-promise.js
CHANGED
|
@@ -92,20 +92,20 @@ var unwrapResponseTask = function (response) {
|
|
|
92
92
|
catch: function (e) { return new fetch_error_1.FetchError({ cause: e }); },
|
|
93
93
|
}));
|
|
94
94
|
};
|
|
95
|
-
exports.fromPromiseTask = effect_1.Effect.withSpan('fromPromiseTask')(effect_1.Effect.gen(function (
|
|
95
|
+
exports.fromPromiseTask = effect_1.Effect.withSpan('fromPromiseTask')(effect_1.Effect.gen(function () {
|
|
96
96
|
var id, response;
|
|
97
97
|
return __generator(this, function (_a) {
|
|
98
98
|
switch (_a.label) {
|
|
99
|
-
case 0: return [5 /*yield**/, __values(
|
|
99
|
+
case 0: return [5 /*yield**/, __values((0, filename_effect_1.filename)(__filename))];
|
|
100
100
|
case 1:
|
|
101
101
|
_a.sent();
|
|
102
|
-
return [5 /*yield**/, __values(
|
|
102
|
+
return [5 /*yield**/, __values(readUser)];
|
|
103
103
|
case 2:
|
|
104
104
|
id = (_a.sent()).id;
|
|
105
|
-
return [5 /*yield**/, __values(
|
|
105
|
+
return [5 /*yield**/, __values(fetchTask(id))];
|
|
106
106
|
case 3:
|
|
107
107
|
response = _a.sent();
|
|
108
|
-
return [5 /*yield**/, __values(
|
|
108
|
+
return [5 /*yield**/, __values(unwrapResponseTask(response))];
|
|
109
109
|
case 4: return [2 /*return*/, _a.sent()];
|
|
110
110
|
}
|
|
111
111
|
});
|
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.3",
|
|
6
6
|
"author": "jpb06 <jp.bois.06@outlook.fr>",
|
|
7
7
|
"description": "A POC for errors reporting in Effect",
|
|
8
8
|
"keywords": [],
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"run-examples": "bun run ./src/examples/util/run-all"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@effect/schema": "^0.66.
|
|
30
|
+
"@effect/schema": "^0.66.8",
|
|
31
31
|
"chalk": "<5",
|
|
32
|
-
"effect": "^3.0.
|
|
32
|
+
"effect": "^3.0.5"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@eslint/eslintrc": "^3.0.2",
|
|
@@ -39,28 +39,28 @@
|
|
|
39
39
|
"@types/eslint": "^8.56.10",
|
|
40
40
|
"@types/fs-extra": "^11.0.4",
|
|
41
41
|
"@types/node": "^20.12.7",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^7.7.
|
|
43
|
-
"@typescript-eslint/parser": "^7.7.
|
|
44
|
-
"@vitest/coverage-v8": "^1.5.
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
43
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
44
|
+
"@vitest/coverage-v8": "^1.5.2",
|
|
45
45
|
"copyfiles": "^2.4.1",
|
|
46
46
|
"del-cli": "^5.1.0",
|
|
47
|
-
"eslint": "^9.1.
|
|
47
|
+
"eslint": "^9.1.1",
|
|
48
48
|
"eslint-config-prettier": "^9.1.0",
|
|
49
49
|
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
50
50
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
51
51
|
"eslint-plugin-import": "^2.29.1",
|
|
52
52
|
"eslint-plugin-markdown": "^4.0.1",
|
|
53
|
-
"eslint-plugin-n": "^17.
|
|
53
|
+
"eslint-plugin-n": "^17.3.1",
|
|
54
54
|
"eslint-plugin-prettier": "^5.1.3",
|
|
55
55
|
"eslint-plugin-promise": "^6.1.1",
|
|
56
|
-
"eslint-plugin-vitest": "^0.5.
|
|
56
|
+
"eslint-plugin-vitest": "^0.5.4",
|
|
57
57
|
"fs-extra": "^11.2.0",
|
|
58
58
|
"globals": "^15.0.0",
|
|
59
59
|
"prettier": "^3.2.5",
|
|
60
60
|
"readme-package-icons": "^1.1.14",
|
|
61
61
|
"typescript": "*",
|
|
62
|
-
"typescript-eslint": "^7.7.
|
|
63
|
-
"vitest": "^1.5.
|
|
62
|
+
"typescript-eslint": "^7.7.1",
|
|
63
|
+
"vitest": "^1.5.2",
|
|
64
64
|
"vitest-mock-extended": "^1.3.1"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/pretty-print.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Cause } from 'effect/Cause';
|
|
2
2
|
import { type PrettyPrintOptions } from './types/pretty-print-options.type';
|
|
3
|
-
export declare const prettyPrint: <E>(cause: Cause<E>, { stripCwd }?: PrettyPrintOptions) => string;
|
|
3
|
+
export declare const prettyPrint: <E>(cause: Cause<E>, { stripCwd, reverseSpans }?: PrettyPrintOptions) => string;
|
package/pretty-print.js
CHANGED
|
@@ -15,7 +15,7 @@ var filter_stack_1 = require("./logic/stack/filter-stack");
|
|
|
15
15
|
var strip_cwd_path_1 = require("./logic/strip-cwd-path");
|
|
16
16
|
var pretty_print_options_type_1 = require("./types/pretty-print-options.type");
|
|
17
17
|
var prettyPrint = function (cause, _a) {
|
|
18
|
-
var _b = _a === void 0 ? pretty_print_options_type_1.prettyPrintOptionsDefault : _a, stripCwd = _b.stripCwd;
|
|
18
|
+
var _b = _a === void 0 ? pretty_print_options_type_1.prettyPrintOptionsDefault : _a, stripCwd = _b.stripCwd, reverseSpans = _b.reverseSpans;
|
|
19
19
|
if ((0, Cause_1.isInterruptedOnly)(cause)) {
|
|
20
20
|
return 'All fibers interrupted without errors.';
|
|
21
21
|
}
|
|
@@ -42,8 +42,8 @@ var prettyPrint = function (cause, _a) {
|
|
|
42
42
|
spans_1.push(current);
|
|
43
43
|
current = effect_1.Option.getOrUndefined(current.parent);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
var orderedSpans = reverseSpans === true ? spans_1.toReversed() : spans_1;
|
|
46
|
+
message += orderedSpans
|
|
47
47
|
.map(function (_a, index) {
|
|
48
48
|
var name = _a.name, attributes = _a.attributes, status = _a.status;
|
|
49
49
|
var isFirstEntry = index === 0;
|
|
File without changes
|