effect-errors 1.2.0 → 1.2.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 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>) => string;
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
- Alternativly, you _can_ use a plain object with a `_tag` and `message` attribute:
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
@@ -1,3 +1,4 @@
1
1
  export * from './pretty-print';
2
2
  export * from './runners/run-promise';
3
3
  export * from './runners/run-sync';
4
+ export * from './types/pretty-print-options.type';
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);
@@ -1 +1 @@
1
- export declare const filterStack: (stack: string) => string;
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 filterStack = function (stack) {
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
- return out.join('\n');
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.0",
5
+ "version": "1.2.1",
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
- export declare const prettyPrint: <E>(cause: Cause<E>) => string;
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
@@ -12,7 +12,10 @@ var get_span_attributes_1 = require("./logic/get-span-attributes");
12
12
  var get_span_duration_1 = require("./logic/get-span-duration");
13
13
  var pretty_errors_1 = require("./logic/pretty-errors");
14
14
  var spans_stack_trailing_char_1 = require("./logic/spans-stack-trailing-char");
15
- var prettyPrint = function (cause) {
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
  }
@@ -39,7 +42,7 @@ var prettyPrint = function (cause) {
39
42
  var name = _a.name, attributes = _a.attributes, status = _a.status;
40
43
  var isFirstEntry = index === 0;
41
44
  var isLastEntry = index === spans_1.length - 1;
42
- var filePath = " at ".concat(name.replace(new RegExp(process.cwd()), '.'));
45
+ var filePath = " at ".concat(stripCwd ? (0, strip_cwd_path_1.stripCwdPath)(name) : name);
43
46
  return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
44
47
  '\r\n' +
45
48
  (0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
@@ -51,7 +54,7 @@ var prettyPrint = function (cause) {
51
54
  .join('');
52
55
  }
53
56
  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).replace(/ {4}at /g, '🭳 at ')));
57
+ 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
58
  }
56
59
  return message + '\r\n';
57
60
  })
@@ -1,2 +1,3 @@
1
1
  import { Effect } from 'effect';
2
- export declare const runPromise: <A, E>(effect: Effect.Effect<A, E>) => Promise<A>;
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>;
@@ -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 runPromise = function (effect) {
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);
@@ -1,2 +1,3 @@
1
1
  import { Effect } from 'effect';
2
- export declare const runSync: <A, E>(effect: Effect.Effect<A, E>) => A;
2
+ import { PrettyPrintOptions } from '../types/pretty-print-options.type';
3
+ export declare const runSync: <A, E>(effect: Effect.Effect<A, E>, options?: PrettyPrintOptions) => A;
@@ -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 runSync = function (effect) {
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);
@@ -0,0 +1,4 @@
1
+ export interface PrettyPrintOptions {
2
+ stripCwd: boolean;
3
+ }
4
+ export declare const prettyPrintOptionsDefault: PrettyPrintOptions;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prettyPrintOptionsDefault = void 0;
4
+ exports.prettyPrintOptionsDefault = {
5
+ stripCwd: false,
6
+ };