effect-errors 1.1.4 → 1.2.0

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.
@@ -9,6 +9,7 @@ var getSpanDuration = function (status, isLastEntry) {
9
9
  if (status._tag !== 'Ended') {
10
10
  return '';
11
11
  }
12
- return "\r\n".concat(isLastEntry ? ' ' : chalk_1.default.gray('│'), " ~ ").concat((status.endTime - status.startTime) / BigInt(100000), "ms");
12
+ var duration = (status.endTime - status.startTime) / BigInt(1000000);
13
+ return "\r\n".concat(isLastEntry ? ' ' : chalk_1.default.gray('│'), " ~ ").concat(duration, "ms");
13
14
  };
14
15
  exports.getSpanDuration = getSpanDuration;
@@ -25,19 +25,19 @@ var Function_1 = require("effect/Function");
25
25
  var Predicate_1 = require("effect/Predicate");
26
26
  var prettyErrorMessage = function (u) {
27
27
  if (typeof u === 'string') {
28
- return "\uD83D\uDCA5 ".concat(u, "\r\n\r\n\u2139\uFE0F ").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.'));
28
+ return "".concat(u, "\r\n\r\n\u2139\uFE0F ").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.'));
29
29
  }
30
30
  // TaggedError with cause
31
31
  if (u instanceof Error && (0, Predicate_1.hasProperty)(u, 'cause') && (0, Predicate_1.hasProperty)(u, '_tag')) {
32
- return "\uD83D\uDCA5 ".concat(chalk_1.default.bgRed(" ".concat(u._tag, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(u.cause)), "\r\n");
32
+ return "".concat(chalk_1.default.bgRed(" ".concat(u._tag, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(u.cause)), "\r\n");
33
33
  }
34
34
  // TaggedError with error ctor
35
35
  if (u instanceof Error && (0, Predicate_1.hasProperty)(u, 'error')) {
36
- return "\uD83D\uDCA5 ".concat(chalk_1.default.bgRed(" ".concat(u.name, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(u.error)), "\r\n");
36
+ return "".concat(chalk_1.default.bgRed(" ".concat(u.name, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(u.error)), "\r\n");
37
37
  }
38
38
  // Plain objects with tag attribute
39
39
  if ((0, Predicate_1.hasProperty)(u, '_tag') && (0, Predicate_1.hasProperty)(u, 'message')) {
40
- return "\uD83D\uDCA5 ".concat(chalk_1.default.bgRed(" ".concat(u._tag, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(u.message)), "\r\n");
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
42
  if ((0, Predicate_1.hasProperty)(u, 'toString') &&
43
43
  (0, Function_1.isFunction)(u['toString']) &&
@@ -47,9 +47,9 @@ var prettyErrorMessage = function (u) {
47
47
  var maybeWithUnderlyingType = message.split(': ');
48
48
  if (maybeWithUnderlyingType.length > 1) {
49
49
  var _a = __read(maybeWithUnderlyingType), type = _a[0], message_1 = _a.slice(1);
50
- return "\uD83D\uDCA5 ".concat(chalk_1.default.bgRed(" ".concat(type, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(message_1)));
50
+ return "".concat(chalk_1.default.bgRed(" ".concat(type, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(message_1)));
51
51
  }
52
- return "\uD83D\uDCA5 ".concat(message);
52
+ return "".concat(message);
53
53
  }
54
54
  return "Error: ".concat(JSON.stringify(u));
55
55
  };
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.1.4",
5
+ "version": "1.2.0",
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.js CHANGED
@@ -19,7 +19,7 @@ var prettyPrint = function (cause) {
19
19
  var failures = (0, pretty_errors_1.prettyErrors)(cause);
20
20
  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
21
  return failures
22
- .map(function (_a) {
22
+ .map(function (_a, failuresIndex) {
23
23
  var message = _a.message, stack = _a.stack, span = _a.span;
24
24
  if (span) {
25
25
  var current = span;
@@ -28,21 +28,27 @@ var prettyPrint = function (cause) {
28
28
  spans_1.push(current);
29
29
  current = effect_1.Option.getOrUndefined(current.parent);
30
30
  }
31
- message += spans_1
32
- .map(function (_a, index) {
33
- var name = _a.name, attributes = _a.attributes, status = _a.status;
34
- var isFirstEntry = index === 0;
35
- var isLastEntry = index === spans_1.length - 1;
36
- var filePath = " at ".concat(name.replace(new RegExp(process.cwd()), '.'));
37
- return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
38
- '\r\n' +
39
- (0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
40
- chalk_1.default.gray('─') +
41
- filePath +
42
- (0, get_span_duration_1.getSpanDuration)(status, isLastEntry) +
43
- (0, get_span_attributes_1.getSpanAttributes)(attributes, isLastEntry));
44
- })
45
- .join('');
31
+ message =
32
+ '💥 ' +
33
+ (failures.length > 1
34
+ ? "".concat(chalk_1.default.bgRed.whiteBright(" #".concat(failuresIndex + 1, " -")))
35
+ : '') +
36
+ message +
37
+ spans_1
38
+ .map(function (_a, index) {
39
+ var name = _a.name, attributes = _a.attributes, status = _a.status;
40
+ var isFirstEntry = index === 0;
41
+ var isLastEntry = index === spans_1.length - 1;
42
+ var filePath = " at ".concat(name.replace(new RegExp(process.cwd()), '.'));
43
+ return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
44
+ '\r\n' +
45
+ (0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
46
+ chalk_1.default.gray('─') +
47
+ filePath +
48
+ (0, get_span_duration_1.getSpanDuration)(status, isLastEntry) +
49
+ (0, get_span_attributes_1.getSpanAttributes)(attributes, isLastEntry));
50
+ })
51
+ .join('');
46
52
  }
47
53
  if (stack) {
48
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 ')));