effect-errors 1.2.0 → 1.2.2
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 +8 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/logic/errors/capture-errors-from-cause.d.ts +3 -0
- package/logic/{pretty-errors.js → errors/capture-errors-from-cause.js} +6 -6
- package/logic/errors/parse-error.d.ts +2 -0
- package/logic/{default-render-error.js → errors/parse-error.js} +4 -4
- package/logic/{pretty-error-message.js → errors/pretty-error-message.js} +1 -0
- package/logic/{get-span-attributes.js → spans/get-span-attributes.js} +3 -2
- package/logic/stack/filter-stack.d.ts +1 -0
- package/logic/{filter-stack.js → stack/filter-stack.js} +4 -2
- package/logic/strip-cwd-path.d.ts +1 -0
- package/logic/strip-cwd-path.js +6 -0
- package/package.json +1 -1
- package/pretty-print.d.ts +2 -1
- package/pretty-print.js +13 -9
- package/runners/run-promise.d.ts +2 -1
- package/runners/run-promise.js +4 -2
- package/runners/run-sync.d.ts +2 -1
- package/runners/run-sync.js +4 -2
- package/types/pretty-print-options.type.d.ts +4 -0
- package/types/pretty-print-options.type.js +6 -0
- package/logic/default-render-error.d.ts +0 -2
- package/logic/filter-stack.d.ts +0 -1
- package/logic/pretty-errors.d.ts +0 -3
- /package/logic/{pretty-error-message.d.ts → errors/pretty-error-message.d.ts} +0 -0
- /package/logic/{get-span-attributes.d.ts → spans/get-span-attributes.d.ts} +0 -0
- /package/logic/{get-span-duration.d.ts → spans/get-span-duration.d.ts} +0 -0
- /package/logic/{get-span-duration.js → spans/get-span-duration.js} +0 -0
- /package/logic/{spans-stack-trailing-char.d.ts → spans/spans-stack-trailing-char.d.ts} +0 -0
- /package/logic/{spans-stack-trailing-char.js → spans/spans-stack-trailing-char.js} +0 -0
package/README.md
CHANGED
|
@@ -41,9 +41,15 @@ import { prettyPrint } from 'effect-errors';
|
|
|
41
41
|
Signature is the following:
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
|
-
const prettyPrint: <E>(cause: Cause<E
|
|
44
|
+
const prettyPrint: <E>(cause: Cause<E>, options?: PrettyPrintOptions) => string;
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
`PrettyPrintOptions` allows you to tweak the following:
|
|
48
|
+
|
|
49
|
+
#### `stripCwd` - Whether spans and stacktrace should contain absolute or relative paths
|
|
50
|
+
|
|
51
|
+
> default: `false` (absolute paths)
|
|
52
|
+
|
|
47
53
|
## ⚡ How should I raise errors?
|
|
48
54
|
|
|
49
55
|
The best way is to use either `SchemaError` or `TaggedError`.
|
|
@@ -97,7 +103,7 @@ Effect.fail(new UserNotFoundError({ cause: "User does not exist" }));
|
|
|
97
103
|
|
|
98
104
|
### 🔶 Plain object
|
|
99
105
|
|
|
100
|
-
|
|
106
|
+
Alternatively, you _can_ use a plain object with a `_tag` and `message` attribute, but you won't get any stacktrace if you use this method:
|
|
101
107
|
|
|
102
108
|
```typescript
|
|
103
109
|
Effect.fail({ _tag: 'SucksToBeMe', message: 'Yeah...' });
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./pretty-print"), exports);
|
|
18
18
|
__exportStar(require("./runners/run-promise"), exports);
|
|
19
19
|
__exportStar(require("./runners/run-sync"), exports);
|
|
20
|
+
__exportStar(require("./types/pretty-print-options.type"), exports);
|
|
@@ -25,17 +25,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
25
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.
|
|
28
|
+
exports.captureErrorsFrom = void 0;
|
|
29
29
|
var Cause_1 = require("effect/Cause");
|
|
30
|
-
var
|
|
31
|
-
var
|
|
30
|
+
var parse_error_1 = require("./parse-error");
|
|
31
|
+
var captureErrorsFrom = function (cause) {
|
|
32
32
|
return (0, Cause_1.reduceWithContext)(cause, void 0, {
|
|
33
33
|
emptyCase: function () { return []; },
|
|
34
|
-
dieCase: function (_, unknownError) { return [(0,
|
|
35
|
-
failCase: function (_, error) { return [(0,
|
|
34
|
+
dieCase: function (_, unknownError) { return [(0, parse_error_1.parseError)(unknownError)]; },
|
|
35
|
+
failCase: function (_, error) { return [(0, parse_error_1.parseError)(error)]; },
|
|
36
36
|
interruptCase: function () { return []; },
|
|
37
37
|
parallelCase: function (_, l, r) { return __spreadArray(__spreadArray([], __read(l), false), __read(r), false); },
|
|
38
38
|
sequentialCase: function (_, l, r) { return __spreadArray(__spreadArray([], __read(l), false), __read(r), false); },
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
exports.
|
|
41
|
+
exports.captureErrorsFrom = captureErrorsFrom;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseError = void 0;
|
|
4
4
|
var Predicate_1 = require("effect/Predicate");
|
|
5
|
-
var pretty_error_type_1 = require("
|
|
5
|
+
var pretty_error_type_1 = require("../../types/pretty-error.type");
|
|
6
6
|
var pretty_error_message_1 = require("./pretty-error-message");
|
|
7
7
|
var spanSymbol = Symbol.for('effect/SpanAnnotation');
|
|
8
|
-
var
|
|
8
|
+
var parseError = function (error) {
|
|
9
9
|
var _a;
|
|
10
10
|
var span = ((0, Predicate_1.hasProperty)(error, spanSymbol) && error[spanSymbol]);
|
|
11
11
|
if (error instanceof Error) {
|
|
@@ -13,4 +13,4 @@ var defaultRenderError = function (error) {
|
|
|
13
13
|
}
|
|
14
14
|
return new pretty_error_type_1.PrettyError((0, pretty_error_message_1.prettyErrorMessage)(error), void 0, span);
|
|
15
15
|
};
|
|
16
|
-
exports.
|
|
16
|
+
exports.parseError = parseError;
|
|
@@ -39,6 +39,7 @@ var prettyErrorMessage = function (u) {
|
|
|
39
39
|
if ((0, Predicate_1.hasProperty)(u, '_tag') && (0, Predicate_1.hasProperty)(u, 'message')) {
|
|
40
40
|
return "".concat(chalk_1.default.bgRed(" ".concat(u._tag, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(u.message)), "\r\n");
|
|
41
41
|
}
|
|
42
|
+
// Plain objects with toString impl
|
|
42
43
|
if ((0, Predicate_1.hasProperty)(u, 'toString') &&
|
|
43
44
|
(0, Function_1.isFunction)(u['toString']) &&
|
|
44
45
|
u['toString'] !== Object.prototype.toString &&
|
|
@@ -25,11 +25,12 @@ var getSpanAttributes = function (attributes, isLastEntry) {
|
|
|
25
25
|
if (attributes.size === 0) {
|
|
26
26
|
return '';
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
var formattedAttributes = Array.from(attributes.entries())
|
|
29
29
|
.map(function (_a) {
|
|
30
30
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
31
31
|
return "".concat(isLastEntry ? ' ' : chalk_1.default.gray('│'), " ").concat(chalk_1.default.blue(key)).concat(chalk_1.default.gray(':'), " ").concat(value);
|
|
32
32
|
})
|
|
33
|
-
.join('\r\n')
|
|
33
|
+
.join('\r\n');
|
|
34
|
+
return "".concat("\r\n".concat(formattedAttributes));
|
|
34
35
|
};
|
|
35
36
|
exports.getSpanAttributes = getSpanAttributes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const filterStack: (stack: string, stripCwd: boolean) => string;
|
|
@@ -12,7 +12,8 @@ var __values = (this && this.__values) || function(o) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.filterStack = void 0;
|
|
15
|
-
var
|
|
15
|
+
var strip_cwd_path_1 = require("../strip-cwd-path");
|
|
16
|
+
var filterStack = function (stack, stripCwd) {
|
|
16
17
|
var e_1, _a;
|
|
17
18
|
var lines = stack.split('\n');
|
|
18
19
|
var out = [];
|
|
@@ -32,6 +33,7 @@ var filterStack = function (stack) {
|
|
|
32
33
|
}
|
|
33
34
|
finally { if (e_1) throw e_1.error; }
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
var final = out.join('\n').replace(/ {4}at /g, '🭳 at ');
|
|
37
|
+
return stripCwd ? (0, strip_cwd_path_1.stripCwdPath)(final) : final;
|
|
36
38
|
};
|
|
37
39
|
exports.filterStack = filterStack;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stripCwdPath: (path: string) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripCwdPath = void 0;
|
|
4
|
+
var cwdRegex = new RegExp(process.cwd(), 'g');
|
|
5
|
+
var stripCwdPath = function (path) { return path.replace(cwdRegex, '.'); };
|
|
6
|
+
exports.stripCwdPath = stripCwdPath;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"repository": "https://github.com/jpb06/effect-errors.git",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"name": "effect-errors",
|
|
5
|
-
"version": "1.2.
|
|
5
|
+
"version": "1.2.2",
|
|
6
6
|
"author": "jpb06 <jp.bois.06@outlook.fr>",
|
|
7
7
|
"description": "A POC for errors reporting in Effect",
|
|
8
8
|
"keywords": [],
|
package/pretty-print.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Cause } from 'effect/Cause';
|
|
2
|
-
|
|
2
|
+
import { PrettyPrintOptions } from './types/pretty-print-options.type';
|
|
3
|
+
export declare const prettyPrint: <E>(cause: Cause<E>, { stripCwd }?: PrettyPrintOptions) => string;
|
package/pretty-print.js
CHANGED
|
@@ -7,16 +7,19 @@ exports.prettyPrint = void 0;
|
|
|
7
7
|
var chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
var effect_1 = require("effect");
|
|
9
9
|
var Cause_1 = require("effect/Cause");
|
|
10
|
-
var
|
|
11
|
-
var get_span_attributes_1 = require("./logic/get-span-attributes");
|
|
12
|
-
var get_span_duration_1 = require("./logic/get-span-duration");
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
10
|
+
var capture_errors_from_cause_1 = require("./logic/errors/capture-errors-from-cause");
|
|
11
|
+
var get_span_attributes_1 = require("./logic/spans/get-span-attributes");
|
|
12
|
+
var get_span_duration_1 = require("./logic/spans/get-span-duration");
|
|
13
|
+
var spans_stack_trailing_char_1 = require("./logic/spans/spans-stack-trailing-char");
|
|
14
|
+
var filter_stack_1 = require("./logic/stack/filter-stack");
|
|
15
|
+
var strip_cwd_path_1 = require("./logic/strip-cwd-path");
|
|
16
|
+
var pretty_print_options_type_1 = require("./types/pretty-print-options.type");
|
|
17
|
+
var prettyPrint = function (cause, _a) {
|
|
18
|
+
var _b = _a === void 0 ? pretty_print_options_type_1.prettyPrintOptionsDefault : _a, stripCwd = _b.stripCwd;
|
|
16
19
|
if ((0, Cause_1.isInterruptedOnly)(cause)) {
|
|
17
20
|
return 'All fibers interrupted without errors.';
|
|
18
21
|
}
|
|
19
|
-
var failures = (0,
|
|
22
|
+
var failures = (0, capture_errors_from_cause_1.captureErrorsFrom)(cause);
|
|
20
23
|
console.error("\r\n\uD83E\uDEE0 ".concat(chalk_1.default.bold.yellowBright.underline("".concat(failures.length, " error").concat(failures.length > 1 ? 's' : '', " occurred\n"))));
|
|
21
24
|
return failures
|
|
22
25
|
.map(function (_a, failuresIndex) {
|
|
@@ -35,11 +38,12 @@ var prettyPrint = function (cause) {
|
|
|
35
38
|
: '') +
|
|
36
39
|
message +
|
|
37
40
|
spans_1
|
|
41
|
+
.reverse()
|
|
38
42
|
.map(function (_a, index) {
|
|
39
43
|
var name = _a.name, attributes = _a.attributes, status = _a.status;
|
|
40
44
|
var isFirstEntry = index === 0;
|
|
41
45
|
var isLastEntry = index === spans_1.length - 1;
|
|
42
|
-
var filePath = " at ".concat(
|
|
46
|
+
var filePath = " at ".concat(stripCwd ? (0, strip_cwd_path_1.stripCwdPath)(name) : name);
|
|
43
47
|
return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
|
|
44
48
|
'\r\n' +
|
|
45
49
|
(0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
|
|
@@ -51,7 +55,7 @@ var prettyPrint = function (cause) {
|
|
|
51
55
|
.join('');
|
|
52
56
|
}
|
|
53
57
|
if (stack) {
|
|
54
|
-
message += "\r\n".concat(span ? '\r\n' : '', "\uD83D\uDEA8 Stacktrace\r\n").concat(chalk_1.default.red((0, filter_stack_1.filterStack)(stack
|
|
58
|
+
message += "\r\n".concat(span ? '\r\n' : '', "\uD83D\uDEA8 Stacktrace\r\n").concat(chalk_1.default.red((0, filter_stack_1.filterStack)(stack, stripCwd)));
|
|
55
59
|
}
|
|
56
60
|
return message + '\r\n';
|
|
57
61
|
})
|
package/runners/run-promise.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
|
|
2
|
+
import { PrettyPrintOptions } from '../types/pretty-print-options.type';
|
|
3
|
+
export declare const runPromise: <A, E>(effect: Effect.Effect<A, E>, options?: PrettyPrintOptions) => Promise<A>;
|
package/runners/run-promise.js
CHANGED
|
@@ -4,10 +4,12 @@ exports.runPromise = void 0;
|
|
|
4
4
|
var effect_1 = require("effect");
|
|
5
5
|
var __1 = require("..");
|
|
6
6
|
var pretty_print_enabled_1 = require("../config/pretty-print-enabled");
|
|
7
|
-
var
|
|
7
|
+
var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
|
|
8
|
+
var runPromise = function (effect, options) {
|
|
9
|
+
if (options === void 0) { options = pretty_print_options_type_1.prettyPrintOptionsDefault; }
|
|
8
10
|
return effect_1.Effect.runPromise((0, effect_1.pipe)(effect, effect_1.Effect.sandbox, effect_1.Effect.catchAll(function (e) {
|
|
9
11
|
if (pretty_print_enabled_1.prettyPrintEnabled) {
|
|
10
|
-
console.error((0, __1.prettyPrint)(e));
|
|
12
|
+
console.error((0, __1.prettyPrint)(e, options));
|
|
11
13
|
return effect_1.Effect.fail('❌ runPromise failure');
|
|
12
14
|
}
|
|
13
15
|
return effect_1.Effect.fail(e);
|
package/runners/run-sync.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
|
|
2
|
+
import { PrettyPrintOptions } from '../types/pretty-print-options.type';
|
|
3
|
+
export declare const runSync: <A, E>(effect: Effect.Effect<A, E>, options?: PrettyPrintOptions) => A;
|
package/runners/run-sync.js
CHANGED
|
@@ -4,10 +4,12 @@ exports.runSync = void 0;
|
|
|
4
4
|
var effect_1 = require("effect");
|
|
5
5
|
var __1 = require("..");
|
|
6
6
|
var pretty_print_enabled_1 = require("../config/pretty-print-enabled");
|
|
7
|
-
var
|
|
7
|
+
var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
|
|
8
|
+
var runSync = function (effect, options) {
|
|
9
|
+
if (options === void 0) { options = pretty_print_options_type_1.prettyPrintOptionsDefault; }
|
|
8
10
|
return effect_1.Effect.runSync((0, effect_1.pipe)(effect, effect_1.Effect.sandbox, effect_1.Effect.catchAll(function (e) {
|
|
9
11
|
if (pretty_print_enabled_1.prettyPrintEnabled) {
|
|
10
|
-
console.error((0, __1.prettyPrint)(e));
|
|
12
|
+
console.error((0, __1.prettyPrint)(e, options));
|
|
11
13
|
return effect_1.Effect.fail('❌ runSync failure');
|
|
12
14
|
}
|
|
13
15
|
return effect_1.Effect.fail(e);
|
package/logic/filter-stack.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const filterStack: (stack: string) => string;
|
package/logic/pretty-errors.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|