effect-errors 1.3.0 → 1.3.1
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 +1 -1
- package/capture-errors.d.ts +3 -3
- package/capture-errors.js +2 -2
- package/caputre-errors.test.js +31 -29
- package/examples/from-promise.js +27 -3
- package/examples/parallel-errors.js +43 -1
- package/logic/errors/capture-errors-from-cause.d.ts +2 -2
- package/logic/errors/capture-errors-from-cause.js +1 -1
- package/logic/errors/extract-error-details.d.ts +1 -1
- package/logic/errors/extract-error-details.js +9 -5
- package/logic/errors/parse-error.js +5 -3
- package/logic/spans/get-span-duration.d.ts +1 -1
- package/logic/strip-cwd-path.js +1 -1
- package/package.json +21 -13
- package/pretty-print.d.ts +2 -2
- package/pretty-print.js +8 -7
- package/runners/run-promise.d.ts +1 -1
- package/runners/run-promise.js +81 -9
- package/runners/run-sync.d.ts +1 -1
- package/runners/run-sync.js +1 -1
- package/tests/mocks/console.mock.d.ts +1 -1
- package/tests/runners/effect-cause.js +44 -3
- package/types/pretty-error.type.d.ts +3 -3
- package/types/pretty-error.type.js +2 -2
package/README.md
CHANGED
package/capture-errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Cause } from 'effect/Cause';
|
|
2
|
-
import { SpanStatus } from 'effect/Tracer';
|
|
1
|
+
import { type Cause } from 'effect/Cause';
|
|
2
|
+
import { type SpanStatus } from 'effect/Tracer';
|
|
3
3
|
export interface ErrorSpan {
|
|
4
4
|
name: string;
|
|
5
5
|
attributes: ReadonlyMap<string, unknown>;
|
|
@@ -10,7 +10,7 @@ export interface ErrorData {
|
|
|
10
10
|
message: unknown;
|
|
11
11
|
stack?: string;
|
|
12
12
|
spans?: ErrorSpan[];
|
|
13
|
-
isPlainString
|
|
13
|
+
isPlainString: boolean;
|
|
14
14
|
}
|
|
15
15
|
export interface CapturedErrors {
|
|
16
16
|
interrupted: boolean;
|
package/capture-errors.js
CHANGED
|
@@ -14,9 +14,9 @@ var captureErrors = function (cause) {
|
|
|
14
14
|
var errors = (0, capture_errors_from_cause_1.captureErrorsFrom)(cause).map(function (_a) {
|
|
15
15
|
var message = _a.message, stack = _a.stack, span = _a.span, errorType = _a.errorType, isPlainString = _a.isPlainString;
|
|
16
16
|
var spans = [];
|
|
17
|
-
if (span) {
|
|
17
|
+
if (span !== undefined) {
|
|
18
18
|
var current = span;
|
|
19
|
-
while (current && current._tag === 'Span') {
|
|
19
|
+
while (current !== undefined && current._tag === 'Span') {
|
|
20
20
|
var name_1 = current.name, attributes = current.attributes, status_1 = current.status;
|
|
21
21
|
spans.push({
|
|
22
22
|
name: name_1,
|
package/caputre-errors.test.js
CHANGED
|
@@ -42,7 +42,7 @@ var from_promise_1 = require("./examples/from-promise");
|
|
|
42
42
|
var parallel_errors_1 = require("./examples/parallel-errors");
|
|
43
43
|
var console_mock_1 = require("./tests/mocks/console.mock");
|
|
44
44
|
var effect_cause_1 = require("./tests/runners/effect-cause");
|
|
45
|
-
(0, console_mock_1.mockConsole)({
|
|
45
|
+
void (0, console_mock_1.mockConsole)({
|
|
46
46
|
info: vitest_1.vi.fn(),
|
|
47
47
|
});
|
|
48
48
|
(0, vitest_1.describe)('captureErrors function', function () {
|
|
@@ -58,95 +58,97 @@ var effect_cause_1 = require("./tests/runners/effect-cause");
|
|
|
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;
|
|
60
60
|
(0, vitest_1.expect)(errorType).toBe('FetchError');
|
|
61
|
-
(0, vitest_1.expect)(isPlainString).
|
|
61
|
+
(0, vitest_1.expect)(isPlainString).toBe(false);
|
|
62
62
|
(0, vitest_1.expect)(message.toString()).toStrictEqual('TypeError: fetch failed');
|
|
63
63
|
(0, vitest_1.expect)(spans).toHaveLength(2);
|
|
64
|
-
(0, vitest_1.expect)(spans[0].name).toBe('fetchUser');
|
|
65
|
-
(0, vitest_1.expect)(spans[0].attributes).toHaveAttributes([
|
|
64
|
+
(0, vitest_1.expect)(spans === null || spans === void 0 ? void 0 : spans[0].name).toBe('fetchUser');
|
|
65
|
+
(0, vitest_1.expect)(spans === null || spans === void 0 ? void 0 : spans[0].attributes).toHaveAttributes([
|
|
66
66
|
{
|
|
67
67
|
key: 'userId',
|
|
68
68
|
value: '123',
|
|
69
69
|
},
|
|
70
70
|
]);
|
|
71
|
-
(0, vitest_1.expect)(spans[1].attributes).toHaveAttributes([]);
|
|
71
|
+
(0, vitest_1.expect)(spans === null || spans === void 0 ? void 0 : spans[1].attributes).toHaveAttributes([]);
|
|
72
72
|
(0, vitest_1.expect)(stack).not.toHaveLength(0);
|
|
73
73
|
return [2 /*return*/];
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
}); });
|
|
77
|
+
// eslint-disable-next-line complexity
|
|
77
78
|
(0, vitest_1.it)('should capture parallel errors', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
79
|
var cause, result, firstError, secondError, thirdError;
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
81
|
+
return __generator(this, function (_u) {
|
|
82
|
+
switch (_u.label) {
|
|
81
83
|
case 0: return [4 /*yield*/, (0, effect_cause_1.effectCause)(parallel_errors_1.withParallelErrorsTask)];
|
|
82
84
|
case 1:
|
|
83
|
-
cause =
|
|
85
|
+
cause = _u.sent();
|
|
84
86
|
result = (0, capture_errors_1.captureErrors)(cause);
|
|
85
87
|
(0, vitest_1.expect)(result.interrupted).toBe(false);
|
|
86
88
|
(0, vitest_1.expect)(result.errors).toHaveLength(3);
|
|
87
89
|
firstError = result.errors[0];
|
|
88
90
|
(0, vitest_1.expect)(firstError.errorType).toBe('UserNotFound');
|
|
89
|
-
(0, vitest_1.expect)(firstError.isPlainString).
|
|
91
|
+
(0, vitest_1.expect)(firstError.isPlainString).toBe(false);
|
|
90
92
|
(0, vitest_1.expect)(firstError.message).toStrictEqual('Oh no, this user does no exist!');
|
|
91
93
|
(0, vitest_1.expect)(firstError.spans).toHaveLength(3);
|
|
92
|
-
(0, vitest_1.expect)(firstError.spans[0].name).toBe('readUser');
|
|
93
|
-
(0, vitest_1.expect)(firstError.spans[0].attributes).toHaveAttributes([
|
|
94
|
+
(0, vitest_1.expect)((_a = firstError.spans) === null || _a === void 0 ? void 0 : _a[0].name).toBe('readUser');
|
|
95
|
+
(0, vitest_1.expect)((_b = firstError.spans) === null || _b === void 0 ? void 0 : _b[0].attributes).toHaveAttributes([
|
|
94
96
|
{
|
|
95
97
|
key: 'name',
|
|
96
98
|
value: 'yolo',
|
|
97
99
|
},
|
|
98
100
|
]);
|
|
99
|
-
(0, vitest_1.expect)(firstError.spans[1].name).toBe('parallelGet');
|
|
100
|
-
(0, vitest_1.expect)(firstError.spans[1].attributes).toHaveAttributes([
|
|
101
|
+
(0, vitest_1.expect)((_c = firstError.spans) === null || _c === void 0 ? void 0 : _c[1].name).toBe('parallelGet');
|
|
102
|
+
(0, vitest_1.expect)((_d = firstError.spans) === null || _d === void 0 ? void 0 : _d[1].attributes).toHaveAttributes([
|
|
101
103
|
{
|
|
102
104
|
key: 'names',
|
|
103
105
|
value: ['yolo', 'bro', 'cool'],
|
|
104
106
|
},
|
|
105
107
|
]);
|
|
106
|
-
(0, vitest_1.expect)(firstError.spans[2].name).toBe('withParallelErrorsTask');
|
|
107
|
-
(0, vitest_1.expect)(firstError.spans[2].attributes).toHaveAttributes([]);
|
|
108
|
+
(0, vitest_1.expect)((_e = firstError.spans) === null || _e === void 0 ? void 0 : _e[2].name).toBe('withParallelErrorsTask');
|
|
109
|
+
(0, vitest_1.expect)((_f = firstError.spans) === null || _f === void 0 ? void 0 : _f[2].attributes).toHaveAttributes([]);
|
|
108
110
|
secondError = result.errors[1];
|
|
109
111
|
(0, vitest_1.expect)(secondError.errorType).toBe('UserNotFound');
|
|
110
|
-
(0, vitest_1.expect)(secondError.isPlainString).
|
|
112
|
+
(0, vitest_1.expect)(secondError.isPlainString).toBe(false);
|
|
111
113
|
(0, vitest_1.expect)(secondError.message).toStrictEqual('Oh no, this user does no exist!');
|
|
112
114
|
(0, vitest_1.expect)(secondError.spans).toHaveLength(3);
|
|
113
|
-
(0, vitest_1.expect)(secondError.spans[0].name).toBe('readUser');
|
|
114
|
-
(0, vitest_1.expect)(secondError.spans[0].attributes).toHaveAttributes([
|
|
115
|
+
(0, vitest_1.expect)((_g = secondError.spans) === null || _g === void 0 ? void 0 : _g[0].name).toBe('readUser');
|
|
116
|
+
(0, vitest_1.expect)((_h = secondError.spans) === null || _h === void 0 ? void 0 : _h[0].attributes).toHaveAttributes([
|
|
115
117
|
{
|
|
116
118
|
key: 'name',
|
|
117
119
|
value: 'bro',
|
|
118
120
|
},
|
|
119
121
|
]);
|
|
120
|
-
(0, vitest_1.expect)(secondError.spans[1].name).toBe('parallelGet');
|
|
121
|
-
(0, vitest_1.expect)(secondError.spans[1].attributes).toHaveAttributes([
|
|
122
|
+
(0, vitest_1.expect)((_j = secondError.spans) === null || _j === void 0 ? void 0 : _j[1].name).toBe('parallelGet');
|
|
123
|
+
(0, vitest_1.expect)((_k = secondError.spans) === null || _k === void 0 ? void 0 : _k[1].attributes).toHaveAttributes([
|
|
122
124
|
{
|
|
123
125
|
key: 'names',
|
|
124
126
|
value: ['yolo', 'bro', 'cool'],
|
|
125
127
|
},
|
|
126
128
|
]);
|
|
127
|
-
(0, vitest_1.expect)(secondError.spans[2].name).toBe('withParallelErrorsTask');
|
|
128
|
-
(0, vitest_1.expect)(secondError.spans[2].attributes).toHaveAttributes([]);
|
|
129
|
+
(0, vitest_1.expect)((_l = secondError.spans) === null || _l === void 0 ? void 0 : _l[2].name).toBe('withParallelErrorsTask');
|
|
130
|
+
(0, vitest_1.expect)((_m = secondError.spans) === null || _m === void 0 ? void 0 : _m[2].attributes).toHaveAttributes([]);
|
|
129
131
|
thirdError = result.errors[2];
|
|
130
132
|
(0, vitest_1.expect)(thirdError.errorType).toBe('UserNotFound');
|
|
131
|
-
(0, vitest_1.expect)(thirdError.isPlainString).
|
|
133
|
+
(0, vitest_1.expect)(thirdError.isPlainString).toBe(false);
|
|
132
134
|
(0, vitest_1.expect)(thirdError.message).toStrictEqual('Oh no, this user does no exist!');
|
|
133
135
|
(0, vitest_1.expect)(thirdError.spans).toHaveLength(3);
|
|
134
|
-
(0, vitest_1.expect)(thirdError.spans[0].name).toBe('readUser');
|
|
135
|
-
(0, vitest_1.expect)(thirdError.spans[0].attributes).toHaveAttributes([
|
|
136
|
+
(0, vitest_1.expect)((_o = thirdError.spans) === null || _o === void 0 ? void 0 : _o[0].name).toBe('readUser');
|
|
137
|
+
(0, vitest_1.expect)((_p = thirdError.spans) === null || _p === void 0 ? void 0 : _p[0].attributes).toHaveAttributes([
|
|
136
138
|
{
|
|
137
139
|
key: 'name',
|
|
138
140
|
value: 'cool',
|
|
139
141
|
},
|
|
140
142
|
]);
|
|
141
|
-
(0, vitest_1.expect)(thirdError.spans[1].name).toBe('parallelGet');
|
|
142
|
-
(0, vitest_1.expect)(thirdError.spans[1].attributes).toHaveAttributes([
|
|
143
|
+
(0, vitest_1.expect)((_q = thirdError.spans) === null || _q === void 0 ? void 0 : _q[1].name).toBe('parallelGet');
|
|
144
|
+
(0, vitest_1.expect)((_r = thirdError.spans) === null || _r === void 0 ? void 0 : _r[1].attributes).toHaveAttributes([
|
|
143
145
|
{
|
|
144
146
|
key: 'names',
|
|
145
147
|
value: ['yolo', 'bro', 'cool'],
|
|
146
148
|
},
|
|
147
149
|
]);
|
|
148
|
-
(0, vitest_1.expect)(thirdError.spans[2].name).toBe('withParallelErrorsTask');
|
|
149
|
-
(0, vitest_1.expect)(thirdError.spans[2].attributes).toHaveAttributes([]);
|
|
150
|
+
(0, vitest_1.expect)((_s = thirdError.spans) === null || _s === void 0 ? void 0 : _s[2].name).toBe('withParallelErrorsTask');
|
|
151
|
+
(0, vitest_1.expect)((_t = thirdError.spans) === null || _t === void 0 ? void 0 : _t[2].attributes).toHaveAttributes([]);
|
|
150
152
|
return [2 /*return*/];
|
|
151
153
|
}
|
|
152
154
|
});
|
package/examples/from-promise.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
12
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
13
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
@@ -45,7 +54,12 @@ var fetch_error_1 = require("./errors/fetch-error");
|
|
|
45
54
|
var file_error_1 = require("./errors/file-error");
|
|
46
55
|
var filename_effect_1 = require("./util/filename.effect");
|
|
47
56
|
var readUser = effect_1.Effect.withSpan('readUser')(effect_1.Effect.tryPromise({
|
|
48
|
-
try: function () { return (0,
|
|
57
|
+
try: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0: return [4 /*yield*/, (0, fs_extra_1.readJson)('./src/examples/data/user.json')];
|
|
60
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
61
|
+
}
|
|
62
|
+
}); }); },
|
|
49
63
|
catch: function (e) { return new file_error_1.FileError({ cause: e }); },
|
|
50
64
|
}));
|
|
51
65
|
var fetchTask = function (userId) {
|
|
@@ -54,7 +68,12 @@ var fetchTask = function (userId) {
|
|
|
54
68
|
userId: userId,
|
|
55
69
|
},
|
|
56
70
|
})(effect_1.Effect.tryPromise({
|
|
57
|
-
try: function () { return
|
|
71
|
+
try: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0: return [4 /*yield*/, fetch("https://yolo-bro-oh-no.org/users/".concat(userId))];
|
|
74
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
75
|
+
}
|
|
76
|
+
}); }); },
|
|
58
77
|
catch: function (e) {
|
|
59
78
|
return new fetch_error_1.FetchError({
|
|
60
79
|
cause: e,
|
|
@@ -64,7 +83,12 @@ var fetchTask = function (userId) {
|
|
|
64
83
|
};
|
|
65
84
|
var unwrapResponseTask = function (response) {
|
|
66
85
|
return effect_1.Effect.withSpan('unwrapFetchUserResponse')(effect_1.Effect.tryPromise({
|
|
67
|
-
try: function () { return
|
|
86
|
+
try: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0: return [4 /*yield*/, response.json()];
|
|
89
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
90
|
+
}
|
|
91
|
+
}); }); },
|
|
68
92
|
catch: function (e) { return new fetch_error_1.FetchError({ cause: e }); },
|
|
69
93
|
}));
|
|
70
94
|
};
|
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.withParallelErrorsTask = void 0;
|
|
4
40
|
var effect_1 = require("effect");
|
|
@@ -10,7 +46,13 @@ var readUser = function (name) {
|
|
|
10
46
|
name: name,
|
|
11
47
|
},
|
|
12
48
|
})(effect_1.Effect.tryPromise({
|
|
13
|
-
|
|
49
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
50
|
+
try: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, Promise.reject('Oh no, this user does no exist!')];
|
|
53
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
54
|
+
}
|
|
55
|
+
}); }); },
|
|
14
56
|
catch: function (e) { return new user_not_found_error_1.UserNotFoundError({ cause: e }); },
|
|
15
57
|
}));
|
|
16
58
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Cause } from 'effect/Cause';
|
|
2
|
-
import { PrettyError } from '../../types/pretty-error.type';
|
|
1
|
+
import { type Cause } from 'effect/Cause';
|
|
2
|
+
import { type PrettyError } from '../../types/pretty-error.type';
|
|
3
3
|
export declare const captureErrorsFrom: <E>(cause: Cause<E>) => readonly PrettyError[];
|
|
@@ -29,7 +29,7 @@ exports.captureErrorsFrom = void 0;
|
|
|
29
29
|
var Cause_1 = require("effect/Cause");
|
|
30
30
|
var parse_error_1 = require("./parse-error");
|
|
31
31
|
var captureErrorsFrom = function (cause) {
|
|
32
|
-
return (0, Cause_1.reduceWithContext)(cause,
|
|
32
|
+
return (0, Cause_1.reduceWithContext)(cause, undefined, {
|
|
33
33
|
emptyCase: function () { return []; },
|
|
34
34
|
dieCase: function (_, unknownError) { return [(0, parse_error_1.parseError)(unknownError)]; },
|
|
35
35
|
failCase: function (_, error) { return [(0, parse_error_1.parseError)(error)]; },
|
|
@@ -31,6 +31,7 @@ var extractErrorDetails = function (error) {
|
|
|
31
31
|
(0, Predicate_1.hasProperty)(error, 'cause') &&
|
|
32
32
|
(0, Predicate_1.hasProperty)(error, '_tag')) {
|
|
33
33
|
return {
|
|
34
|
+
isPlainString: false,
|
|
34
35
|
type: error._tag,
|
|
35
36
|
message: error.cause,
|
|
36
37
|
};
|
|
@@ -38,6 +39,7 @@ var extractErrorDetails = function (error) {
|
|
|
38
39
|
// TaggedError with error ctor
|
|
39
40
|
if (error instanceof Error && (0, Predicate_1.hasProperty)(error, 'error')) {
|
|
40
41
|
return {
|
|
42
|
+
isPlainString: false,
|
|
41
43
|
type: error.name,
|
|
42
44
|
message: error.error,
|
|
43
45
|
};
|
|
@@ -45,26 +47,28 @@ var extractErrorDetails = function (error) {
|
|
|
45
47
|
// Plain objects with tag attribute
|
|
46
48
|
if ((0, Predicate_1.hasProperty)(error, '_tag') && (0, Predicate_1.hasProperty)(error, 'message')) {
|
|
47
49
|
return {
|
|
50
|
+
isPlainString: false,
|
|
48
51
|
type: error._tag,
|
|
49
52
|
message: error.message,
|
|
50
53
|
};
|
|
51
54
|
}
|
|
52
55
|
// Plain objects with toString impl
|
|
53
56
|
if ((0, Predicate_1.hasProperty)(error, 'toString') &&
|
|
54
|
-
(0, Function_1.isFunction)(error
|
|
55
|
-
error
|
|
56
|
-
error
|
|
57
|
+
(0, Function_1.isFunction)(error.toString) &&
|
|
58
|
+
error.toString !== Object.prototype.toString &&
|
|
59
|
+
error.toString !== Array.prototype.toString) {
|
|
57
60
|
var message = error.toString();
|
|
58
61
|
var maybeWithUnderlyingType = message.split(': ');
|
|
59
62
|
if (maybeWithUnderlyingType.length > 1) {
|
|
60
63
|
var _a = __read(maybeWithUnderlyingType), type = _a[0], message_1 = _a.slice(1);
|
|
61
64
|
return {
|
|
65
|
+
isPlainString: false,
|
|
62
66
|
type: type,
|
|
63
67
|
message: message_1,
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
|
-
return { message: message };
|
|
70
|
+
return { message: message, isPlainString: false };
|
|
67
71
|
}
|
|
68
|
-
return { message: "Error: ".concat(JSON.stringify(error)) };
|
|
72
|
+
return { message: "Error: ".concat(JSON.stringify(error)), isPlainString: false };
|
|
69
73
|
};
|
|
70
74
|
exports.extractErrorDetails = extractErrorDetails;
|
|
@@ -7,11 +7,13 @@ var extract_error_details_1 = require("./extract-error-details");
|
|
|
7
7
|
var spanSymbol = Symbol.for('effect/SpanAnnotation');
|
|
8
8
|
var parseError = function (error) {
|
|
9
9
|
var _a;
|
|
10
|
-
var span = (
|
|
10
|
+
var span = (0, Predicate_1.hasProperty)(error, spanSymbol)
|
|
11
|
+
? error[spanSymbol]
|
|
12
|
+
: undefined;
|
|
11
13
|
var _b = (0, extract_error_details_1.extractErrorDetails)(error), message = _b.message, type = _b.type, isPlainString = _b.isPlainString;
|
|
12
14
|
if (error instanceof Error) {
|
|
13
|
-
return new pretty_error_type_1.PrettyError(message, (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n').filter(function (el) { return /at (.*)/.exec(el); }).join('\r\n'), span, type);
|
|
15
|
+
return new pretty_error_type_1.PrettyError(message, (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n').filter(function (el) { return /at (.*)/.exec(el); }).join('\r\n'), span, false, type);
|
|
14
16
|
}
|
|
15
|
-
return new pretty_error_type_1.PrettyError(message,
|
|
17
|
+
return new pretty_error_type_1.PrettyError(message, undefined, span, isPlainString, type);
|
|
16
18
|
};
|
|
17
19
|
exports.parseError = parseError;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SpanStatus } from 'effect/Tracer';
|
|
1
|
+
import { type SpanStatus } from 'effect/Tracer';
|
|
2
2
|
export declare const getSpanDuration: (status: SpanStatus, isLastEntry: boolean) => string;
|
package/logic/strip-cwd-path.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stripCwdPath = void 0;
|
|
4
|
-
var cwdRegex = global.process ? new RegExp(global.process.cwd(), 'g') : null;
|
|
4
|
+
var cwdRegex = global.process !== undefined ? new RegExp(global.process.cwd(), 'g') : null;
|
|
5
5
|
var stripCwdPath = function (path) {
|
|
6
6
|
return cwdRegex === null ? path : path.replace(cwdRegex, '.');
|
|
7
7
|
};
|
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.1",
|
|
6
6
|
"author": "jpb06 <jp.bois.06@outlook.fr>",
|
|
7
7
|
"description": "A POC for errors reporting in Effect",
|
|
8
8
|
"keywords": [],
|
|
@@ -27,32 +27,40 @@
|
|
|
27
27
|
"run-examples": "bun run ./src/examples/util/run-all"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@effect/schema": "^0.
|
|
30
|
+
"@effect/schema": "^0.66.5",
|
|
31
31
|
"chalk": "<5",
|
|
32
|
-
"effect": "^
|
|
32
|
+
"effect": "^3.0.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
35
|
+
"@eslint/eslintrc": "^3.0.2",
|
|
36
|
+
"@eslint/js": "^9.1.1",
|
|
37
|
+
"@stylistic/eslint-plugin": "^1.7.2",
|
|
38
|
+
"@stylistic/eslint-plugin-ts": "^1.7.2",
|
|
39
|
+
"@types/eslint": "^8.56.10",
|
|
37
40
|
"@types/fs-extra": "^11.0.4",
|
|
38
|
-
"@types/node": "^20.12.
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
40
|
-
"@typescript-eslint/parser": "^7.
|
|
41
|
-
"@vitest/coverage-v8": "^1.
|
|
41
|
+
"@types/node": "^20.12.7",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
|
43
|
+
"@typescript-eslint/parser": "^7.7.0",
|
|
44
|
+
"@vitest/coverage-v8": "^1.5.0",
|
|
42
45
|
"copyfiles": "^2.4.1",
|
|
43
46
|
"del-cli": "^5.1.0",
|
|
44
|
-
"eslint": "^
|
|
47
|
+
"eslint": "^9.1.0",
|
|
45
48
|
"eslint-config-prettier": "^9.1.0",
|
|
49
|
+
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
46
50
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
47
51
|
"eslint-plugin-import": "^2.29.1",
|
|
48
52
|
"eslint-plugin-markdown": "^4.0.1",
|
|
53
|
+
"eslint-plugin-n": "^17.2.1",
|
|
49
54
|
"eslint-plugin-prettier": "^5.1.3",
|
|
50
|
-
"eslint-plugin-
|
|
55
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
56
|
+
"eslint-plugin-vitest": "^0.5.3",
|
|
51
57
|
"fs-extra": "^11.2.0",
|
|
58
|
+
"globals": "^15.0.0",
|
|
52
59
|
"prettier": "^3.2.5",
|
|
53
60
|
"readme-package-icons": "^1.1.14",
|
|
54
|
-
"typescript": "
|
|
55
|
-
"
|
|
61
|
+
"typescript": "*",
|
|
62
|
+
"typescript-eslint": "^7.7.0",
|
|
63
|
+
"vitest": "^1.5.0",
|
|
56
64
|
"vitest-mock-extended": "^1.3.1"
|
|
57
65
|
}
|
|
58
66
|
}
|
package/pretty-print.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Cause } from 'effect/Cause';
|
|
2
|
-
import { PrettyPrintOptions } from './types/pretty-print-options.type';
|
|
1
|
+
import { type Cause } from 'effect/Cause';
|
|
2
|
+
import { type PrettyPrintOptions } from './types/pretty-print-options.type';
|
|
3
3
|
export declare const prettyPrint: <E>(cause: Cause<E>, { stripCwd }?: PrettyPrintOptions) => string;
|
package/pretty-print.js
CHANGED
|
@@ -23,21 +23,22 @@ var prettyPrint = function (cause, _a) {
|
|
|
23
23
|
console.error("\r\n\uD83E\uDEE0 ".concat(chalk_1.default.bold.yellowBright.underline("".concat(failures.length, " error").concat(failures.length > 1 ? 's' : '', " occurred\r\n"))));
|
|
24
24
|
return failures
|
|
25
25
|
.map(function (_a, failuresIndex) {
|
|
26
|
+
var _b;
|
|
26
27
|
var errorType = _a.errorType, errorMessage = _a.message, stack = _a.stack, span = _a.span, isPlainString = _a.isPlainString;
|
|
27
28
|
var message = '💥 ' +
|
|
28
29
|
(failures.length > 1
|
|
29
30
|
? chalk_1.default.bgRed.whiteBright(" #".concat(failuresIndex + 1, " -"))
|
|
30
31
|
: '') +
|
|
31
|
-
chalk_1.default.bgRed.whiteBright(" ".concat(errorType !== null &&
|
|
32
|
+
chalk_1.default.bgRed.whiteBright(" ".concat((_b = errorType) !== null && _b !== void 0 ? _b : 'Unknown error', " ")) +
|
|
32
33
|
chalk_1.default.bold.whiteBright(" \u2022 ".concat(errorMessage)) +
|
|
33
34
|
'\r\n';
|
|
34
|
-
if (isPlainString
|
|
35
|
+
if (isPlainString) {
|
|
35
36
|
message += "\r\n".concat(chalk_1.default.gray('ℹ️ You used a plain string to represent a failure in the error channel (E). You should consider using tagged objects (with a _tag field), or yieldable errors such as Data.TaggedError and Schema.TaggedError for better handling experience.'));
|
|
36
37
|
}
|
|
37
|
-
if (span) {
|
|
38
|
+
if (span !== undefined) {
|
|
38
39
|
var current = span;
|
|
39
40
|
var spans_1 = [];
|
|
40
|
-
while (current && current._tag === 'Span') {
|
|
41
|
+
while (current !== undefined && current._tag === 'Span') {
|
|
41
42
|
spans_1.push(current);
|
|
42
43
|
current = effect_1.Option.getOrUndefined(current.parent);
|
|
43
44
|
}
|
|
@@ -47,7 +48,7 @@ var prettyPrint = function (cause, _a) {
|
|
|
47
48
|
var name = _a.name, attributes = _a.attributes, status = _a.status;
|
|
48
49
|
var isFirstEntry = index === 0;
|
|
49
50
|
var isLastEntry = index === spans_1.length - 1;
|
|
50
|
-
var filePath = " at ".concat(stripCwd ? (0, strip_cwd_path_1.stripCwdPath)(name) : name);
|
|
51
|
+
var filePath = " at ".concat(stripCwd !== undefined ? (0, strip_cwd_path_1.stripCwdPath)(name) : name);
|
|
51
52
|
return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
|
|
52
53
|
'\r\n' +
|
|
53
54
|
(0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
|
|
@@ -61,8 +62,8 @@ var prettyPrint = function (cause, _a) {
|
|
|
61
62
|
else if (!isPlainString) {
|
|
62
63
|
message += "\r\n".concat(chalk_1.default.gray('ℹ️ Consider using spans to improve errors reporting.\r\n'));
|
|
63
64
|
}
|
|
64
|
-
if (stack) {
|
|
65
|
-
message += "\r\n".concat(span ? '\r\n' : '', "\uD83D\uDEA8 Stacktrace\r\n").concat(chalk_1.default.red((0, filter_stack_1.filterStack)(stack, stripCwd === true)));
|
|
65
|
+
if (stack !== undefined) {
|
|
66
|
+
message += "\r\n".concat(span !== undefined ? '\r\n' : '', "\uD83D\uDEA8 Stacktrace\r\n").concat(chalk_1.default.red((0, filter_stack_1.filterStack)(stack, stripCwd === true)));
|
|
66
67
|
}
|
|
67
68
|
else if (!isPlainString) {
|
|
68
69
|
message += "\r\n\r\n".concat(chalk_1.default.gray('ℹ️ Consider using a yieldable error such as Data.TaggedError and Schema.TaggedError to get a stacktrace.'));
|
package/runners/run-promise.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { PrettyPrintOptions } from '../types/pretty-print-options.type';
|
|
2
|
+
import { type PrettyPrintOptions } from '../types/pretty-print-options.type';
|
|
3
3
|
export declare const runPromise: <A, E>(effect: Effect.Effect<A, E>, options?: PrettyPrintOptions) => Promise<A>;
|
package/runners/run-promise.js
CHANGED
|
@@ -1,17 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
+
};
|
|
2
63
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
64
|
exports.runPromise = void 0;
|
|
4
65
|
var effect_1 = require("effect");
|
|
5
66
|
var __1 = require("..");
|
|
6
67
|
var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
|
|
7
|
-
var runPromise = function (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
|
|
68
|
+
var runPromise = function (effect_2) {
|
|
69
|
+
var args_1 = [];
|
|
70
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
71
|
+
args_1[_i - 1] = arguments[_i];
|
|
72
|
+
}
|
|
73
|
+
return __awaiter(void 0, __spreadArray([effect_2], __read(args_1), false), void 0, function (effect, options) {
|
|
74
|
+
if (options === void 0) { options = pretty_print_options_type_1.prettyPrintOptionsDefault; }
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0: return [4 /*yield*/, effect_1.Effect.runPromise((0, effect_1.pipe)(effect, effect_1.Effect.sandbox, effect_1.Effect.catchAll(function (e) {
|
|
78
|
+
if (options.enabled === false) {
|
|
79
|
+
return effect_1.Effect.fail(e);
|
|
80
|
+
}
|
|
81
|
+
console.error((0, __1.prettyPrint)(e, options));
|
|
82
|
+
return effect_1.Effect.fail('❌ runPromise failure');
|
|
83
|
+
})))];
|
|
84
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
16
88
|
};
|
|
17
89
|
exports.runPromise = runPromise;
|
package/runners/run-sync.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { PrettyPrintOptions } from '../types/pretty-print-options.type';
|
|
2
|
+
import { type PrettyPrintOptions } from '../types/pretty-print-options.type';
|
|
3
3
|
export declare const runSync: <A, E>(effect: Effect.Effect<A, E>, options?: PrettyPrintOptions) => A;
|
package/runners/run-sync.js
CHANGED
|
@@ -7,7 +7,7 @@ var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
|
|
|
7
7
|
var runSync = function (effect, options) {
|
|
8
8
|
if (options === void 0) { options = pretty_print_options_type_1.prettyPrintOptionsDefault; }
|
|
9
9
|
return effect_1.Effect.runSync((0, effect_1.pipe)(effect, effect_1.Effect.sandbox, effect_1.Effect.catchAll(function (e) {
|
|
10
|
-
if (options.enabled) {
|
|
10
|
+
if (options.enabled === true) {
|
|
11
11
|
console.error((0, __1.prettyPrint)(e, options));
|
|
12
12
|
return effect_1.Effect.fail('❌ runSync failure');
|
|
13
13
|
}
|
|
@@ -1,8 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.effectCause = void 0;
|
|
4
40
|
var effect_1 = require("effect");
|
|
5
|
-
var effectCause = function (effect) {
|
|
6
|
-
return
|
|
7
|
-
|
|
41
|
+
var effectCause = function (effect) { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
switch (_a.label) {
|
|
44
|
+
case 0: return [4 /*yield*/, effect_1.Effect.runPromise((0, effect_1.pipe)(effect, effect_1.Effect.catchAllCause(function (e) { return effect_1.Effect.fail(e); }), effect_1.Effect.flip))];
|
|
45
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}); };
|
|
8
49
|
exports.effectCause = effectCause;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Span } from 'effect/Tracer';
|
|
1
|
+
import { type Span } from 'effect/Tracer';
|
|
2
2
|
export declare class PrettyError {
|
|
3
3
|
readonly message: unknown;
|
|
4
4
|
readonly stack: string | undefined;
|
|
5
5
|
readonly span: Span | undefined;
|
|
6
|
+
readonly isPlainString: boolean;
|
|
6
7
|
readonly errorType?: unknown;
|
|
7
|
-
|
|
8
|
-
constructor(message: unknown, stack: string | undefined, span: Span | undefined, errorType?: unknown, isPlainString?: boolean | undefined);
|
|
8
|
+
constructor(message: unknown, stack: string | undefined, span: Span | undefined, isPlainString: boolean, errorType?: unknown);
|
|
9
9
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PrettyError = void 0;
|
|
4
4
|
var PrettyError = /** @class */ (function () {
|
|
5
|
-
function PrettyError(message, stack, span,
|
|
5
|
+
function PrettyError(message, stack, span, isPlainString, errorType) {
|
|
6
6
|
this.message = message;
|
|
7
7
|
this.stack = stack;
|
|
8
8
|
this.span = span;
|
|
9
|
-
this.errorType = errorType;
|
|
10
9
|
this.isPlainString = isPlainString;
|
|
10
|
+
this.errorType = errorType;
|
|
11
11
|
}
|
|
12
12
|
return PrettyError;
|
|
13
13
|
}());
|