effect-errors 1.3.2 → 1.3.4

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 CHANGED
@@ -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
- type captureErrorsFunction: <E>(cause: Cause<E>) => CapturedErrors
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:
@@ -16,4 +16,7 @@ export interface CapturedErrors {
16
16
  interrupted: boolean;
17
17
  errors: ErrorData[];
18
18
  }
19
- export declare const captureErrors: <E>(cause: Cause<E>) => CapturedErrors;
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/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.2",
5
+ "version": "1.3.4",
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.7",
30
+ "@effect/schema": "^0.66.8",
31
31
  "chalk": "<5",
32
- "effect": "^3.0.4"
32
+ "effect": "^3.0.5"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@eslint/eslintrc": "^3.0.2",
@@ -41,7 +41,7 @@
41
41
  "@types/node": "^20.12.7",
42
42
  "@typescript-eslint/eslint-plugin": "^7.7.1",
43
43
  "@typescript-eslint/parser": "^7.7.1",
44
- "@vitest/coverage-v8": "^1.5.1",
44
+ "@vitest/coverage-v8": "^1.5.2",
45
45
  "copyfiles": "^2.4.1",
46
46
  "del-cli": "^5.1.0",
47
47
  "eslint": "^9.1.1",
@@ -60,7 +60,7 @@
60
60
  "readme-package-icons": "^1.1.14",
61
61
  "typescript": "*",
62
62
  "typescript-eslint": "^7.7.1",
63
- "vitest": "^1.5.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
- message += spans_1
46
- .toReversed()
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;
@@ -1,5 +1,6 @@
1
1
  export interface PrettyPrintOptions {
2
- stripCwd?: boolean;
3
2
  enabled?: boolean;
3
+ stripCwd?: boolean;
4
+ reverseSpans?: boolean;
4
5
  }
5
6
  export declare const prettyPrintOptionsDefault: PrettyPrintOptions;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prettyPrintOptionsDefault = void 0;
4
4
  exports.prettyPrintOptionsDefault = {
5
- stripCwd: false,
6
5
  enabled: true,
6
+ stripCwd: false,
7
+ reverseSpans: true,
7
8
  };