effect-errors 1.4.0 → 1.4.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.
Files changed (169) hide show
  1. package/README.md +2 -2
  2. package/cjs/capture-errors.js +74 -0
  3. package/cjs/capture-errors.js.map +1 -0
  4. package/cjs/index.js +61 -0
  5. package/cjs/index.js.map +1 -0
  6. package/cjs/logic/errors/capture-errors-from-cause.js +18 -0
  7. package/cjs/logic/errors/capture-errors-from-cause.js.map +1 -0
  8. package/cjs/logic/errors/extract-error-details.js +63 -0
  9. package/cjs/logic/errors/extract-error-details.js.map +1 -0
  10. package/cjs/logic/errors/parse-error.js +24 -0
  11. package/cjs/logic/errors/parse-error.js.map +1 -0
  12. package/cjs/logic/pretty-printing/format-failures-title.js +15 -0
  13. package/cjs/logic/pretty-printing/format-failures-title.js.map +1 -0
  14. package/cjs/logic/pretty-printing/format-span-attributes.js +55 -0
  15. package/cjs/logic/pretty-printing/format-span-attributes.js.map +1 -0
  16. package/cjs/logic/pretty-printing/maybe-print-node-stacktrace.js +24 -0
  17. package/cjs/logic/pretty-printing/maybe-print-node-stacktrace.js.map +1 -0
  18. package/cjs/logic/pretty-printing/maybe-print-span-attributes.js +31 -0
  19. package/cjs/logic/pretty-printing/maybe-print-span-attributes.js.map +1 -0
  20. package/cjs/logic/pretty-printing/maybe-warn-about-plain-strings.js +20 -0
  21. package/cjs/logic/pretty-printing/maybe-warn-about-plain-strings.js.map +1 -0
  22. package/cjs/logic/pretty-printing/print-effect-stacktrace.js +24 -0
  23. package/cjs/logic/pretty-printing/print-effect-stacktrace.js.map +1 -0
  24. package/cjs/logic/spans/get-span-attributes.js +33 -0
  25. package/cjs/logic/spans/get-span-attributes.js.map +1 -0
  26. package/cjs/logic/spans/get-span-duration.js +21 -0
  27. package/cjs/logic/spans/get-span-duration.js.map +1 -0
  28. package/cjs/logic/spans/spans-stack-trailing-char.js +15 -0
  29. package/cjs/logic/spans/spans-stack-trailing-char.js.map +1 -0
  30. package/cjs/logic/spans/split-spans-attributes-by-type.js +23 -0
  31. package/cjs/logic/spans/split-spans-attributes-by-type.js.map +1 -0
  32. package/cjs/logic/stack/filter-stack.js +21 -0
  33. package/cjs/logic/stack/filter-stack.js.map +1 -0
  34. package/cjs/logic/strip-cwd-path.js +10 -0
  35. package/cjs/logic/strip-cwd-path.js.map +1 -0
  36. package/cjs/pretty-print.js +43 -0
  37. package/cjs/pretty-print.js.map +1 -0
  38. package/cjs/runners/run-promise.js +18 -0
  39. package/cjs/runners/run-promise.js.map +1 -0
  40. package/cjs/runners/run-sync.js +18 -0
  41. package/cjs/runners/run-sync.js.map +1 -0
  42. package/cjs/types/pretty-error.type.js +22 -0
  43. package/cjs/types/pretty-error.type.js.map +1 -0
  44. package/cjs/types/pretty-print-options.type.js +12 -0
  45. package/cjs/types/pretty-print-options.type.js.map +1 -0
  46. package/{capture-errors.d.ts → dts/capture-errors.d.ts} +3 -2
  47. package/dts/capture-errors.d.ts.map +1 -0
  48. package/dts/index.d.ts +6 -0
  49. package/dts/index.d.ts.map +1 -0
  50. package/{logic → dts/logic}/errors/capture-errors-from-cause.d.ts +1 -0
  51. package/dts/logic/errors/capture-errors-from-cause.d.ts.map +1 -0
  52. package/{logic → dts/logic}/errors/extract-error-details.d.ts +1 -0
  53. package/dts/logic/errors/extract-error-details.d.ts.map +1 -0
  54. package/{logic → dts/logic}/errors/parse-error.d.ts +1 -0
  55. package/dts/logic/errors/parse-error.d.ts.map +1 -0
  56. package/dts/logic/pretty-printing/format-failures-title.d.ts +2 -0
  57. package/dts/logic/pretty-printing/format-failures-title.d.ts.map +1 -0
  58. package/dts/logic/pretty-printing/format-span-attributes.d.ts +7 -0
  59. package/dts/logic/pretty-printing/format-span-attributes.d.ts.map +1 -0
  60. package/dts/logic/pretty-printing/maybe-print-node-stacktrace.d.ts +4 -0
  61. package/dts/logic/pretty-printing/maybe-print-node-stacktrace.d.ts.map +1 -0
  62. package/dts/logic/pretty-printing/maybe-print-span-attributes.d.ts +4 -0
  63. package/dts/logic/pretty-printing/maybe-print-span-attributes.d.ts.map +1 -0
  64. package/dts/logic/pretty-printing/maybe-warn-about-plain-strings.d.ts +2 -0
  65. package/dts/logic/pretty-printing/maybe-warn-about-plain-strings.d.ts.map +1 -0
  66. package/dts/logic/pretty-printing/print-effect-stacktrace.d.ts +4 -0
  67. package/dts/logic/pretty-printing/print-effect-stacktrace.d.ts.map +1 -0
  68. package/{logic → dts/logic}/spans/get-span-attributes.d.ts +1 -0
  69. package/dts/logic/spans/get-span-attributes.d.ts.map +1 -0
  70. package/{logic → dts/logic}/spans/get-span-duration.d.ts +1 -0
  71. package/dts/logic/spans/get-span-duration.d.ts.map +1 -0
  72. package/{logic → dts/logic}/spans/spans-stack-trailing-char.d.ts +1 -0
  73. package/dts/logic/spans/spans-stack-trailing-char.d.ts.map +1 -0
  74. package/{logic → dts/logic}/spans/split-spans-attributes-by-type.d.ts +1 -0
  75. package/dts/logic/spans/split-spans-attributes-by-type.d.ts.map +1 -0
  76. package/{logic → dts/logic}/stack/filter-stack.d.ts +1 -0
  77. package/dts/logic/stack/filter-stack.d.ts.map +1 -0
  78. package/{logic → dts/logic}/strip-cwd-path.d.ts +1 -0
  79. package/dts/logic/strip-cwd-path.d.ts.map +1 -0
  80. package/dts/pretty-print.d.ts +4 -0
  81. package/dts/pretty-print.d.ts.map +1 -0
  82. package/{runners → dts/runners}/run-promise.d.ts +1 -0
  83. package/dts/runners/run-promise.d.ts.map +1 -0
  84. package/{runners → dts/runners}/run-sync.d.ts +1 -0
  85. package/dts/runners/run-sync.d.ts.map +1 -0
  86. package/{types → dts/types}/pretty-error.type.d.ts +1 -0
  87. package/dts/types/pretty-error.type.d.ts.map +1 -0
  88. package/{types → dts/types}/pretty-print-options.type.d.ts +1 -0
  89. package/dts/types/pretty-print-options.type.d.ts.map +1 -0
  90. package/esm/capture-errors.js +67 -0
  91. package/esm/capture-errors.js.map +1 -0
  92. package/{index.d.ts → esm/index.js} +1 -0
  93. package/esm/index.js.map +1 -0
  94. package/esm/logic/errors/capture-errors-from-cause.js +11 -0
  95. package/esm/logic/errors/capture-errors-from-cause.js.map +1 -0
  96. package/esm/logic/errors/extract-error-details.js +56 -0
  97. package/esm/logic/errors/extract-error-details.js.map +1 -0
  98. package/esm/logic/errors/parse-error.js +17 -0
  99. package/esm/logic/errors/parse-error.js.map +1 -0
  100. package/esm/logic/pretty-printing/format-failures-title.js +3 -0
  101. package/esm/logic/pretty-printing/format-failures-title.js.map +1 -0
  102. package/esm/logic/pretty-printing/format-span-attributes.js +43 -0
  103. package/esm/logic/pretty-printing/format-span-attributes.js.map +1 -0
  104. package/esm/logic/pretty-printing/maybe-print-node-stacktrace.js +12 -0
  105. package/esm/logic/pretty-printing/maybe-print-node-stacktrace.js.map +1 -0
  106. package/esm/logic/pretty-printing/maybe-print-span-attributes.js +19 -0
  107. package/esm/logic/pretty-printing/maybe-print-span-attributes.js.map +1 -0
  108. package/esm/logic/pretty-printing/maybe-warn-about-plain-strings.js +8 -0
  109. package/esm/logic/pretty-printing/maybe-warn-about-plain-strings.js.map +1 -0
  110. package/esm/logic/pretty-printing/print-effect-stacktrace.js +12 -0
  111. package/esm/logic/pretty-printing/print-effect-stacktrace.js.map +1 -0
  112. package/esm/logic/spans/get-span-attributes.js +21 -0
  113. package/esm/logic/spans/get-span-attributes.js.map +1 -0
  114. package/esm/logic/spans/get-span-duration.js +9 -0
  115. package/esm/logic/spans/get-span-duration.js.map +1 -0
  116. package/esm/logic/spans/spans-stack-trailing-char.js +3 -0
  117. package/esm/logic/spans/spans-stack-trailing-char.js.map +1 -0
  118. package/esm/logic/spans/split-spans-attributes-by-type.js +16 -0
  119. package/esm/logic/spans/split-spans-attributes-by-type.js.map +1 -0
  120. package/esm/logic/stack/filter-stack.js +14 -0
  121. package/esm/logic/stack/filter-stack.js.map +1 -0
  122. package/esm/logic/strip-cwd-path.js +3 -0
  123. package/esm/logic/strip-cwd-path.js.map +1 -0
  124. package/esm/pretty-print.js +31 -0
  125. package/esm/pretty-print.js.map +1 -0
  126. package/esm/runners/run-promise.js +11 -0
  127. package/esm/runners/run-promise.js.map +1 -0
  128. package/esm/runners/run-sync.js +11 -0
  129. package/esm/runners/run-sync.js.map +1 -0
  130. package/esm/types/pretty-error.type.js +15 -0
  131. package/esm/types/pretty-error.type.js.map +1 -0
  132. package/esm/types/pretty-print-options.type.js +6 -0
  133. package/esm/types/pretty-print-options.type.js.map +1 -0
  134. package/package.json +23 -8
  135. package/capture-errors.js +0 -83
  136. package/capture-errors.test.d.ts +0 -1
  137. package/capture-errors.test.js +0 -169
  138. package/examples/errors/fetch-error.d.ts +0 -9
  139. package/examples/errors/fetch-error.js +0 -27
  140. package/examples/errors/file-error.d.ts +0 -9
  141. package/examples/errors/file-error.js +0 -27
  142. package/examples/errors/user-not-found.error.d.ts +0 -9
  143. package/examples/errors/user-not-found.error.js +0 -27
  144. package/examples/from-promise.d.ts +0 -5
  145. package/examples/from-promise.js +0 -109
  146. package/examples/parallel-errors.d.ts +0 -4
  147. package/examples/parallel-errors.js +0 -69
  148. package/examples/util/filename.effect.d.ts +0 -2
  149. package/examples/util/filename.effect.js +0 -11
  150. package/index.js +0 -21
  151. package/logic/errors/capture-errors-from-cause.js +0 -41
  152. package/logic/errors/extract-error-details.js +0 -74
  153. package/logic/errors/parse-error.js +0 -19
  154. package/logic/spans/get-span-attributes.js +0 -44
  155. package/logic/spans/get-span-duration.js +0 -15
  156. package/logic/spans/spans-stack-trailing-char.js +0 -11
  157. package/logic/spans/split-spans-attributes-by-type.js +0 -47
  158. package/logic/stack/filter-stack.js +0 -39
  159. package/logic/strip-cwd-path.js +0 -8
  160. package/pretty-print.d.ts +0 -3
  161. package/pretty-print.js +0 -107
  162. package/runners/run-promise.js +0 -89
  163. package/runners/run-sync.js +0 -17
  164. package/tests/mocks/console.mock.d.ts +0 -9
  165. package/tests/mocks/console.mock.js +0 -66
  166. package/tests/runners/effect-cause.d.ts +0 -2
  167. package/tests/runners/effect-cause.js +0 -49
  168. package/types/pretty-error.type.js +0 -14
  169. package/types/pretty-print-options.type.js +0 -8
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseError = void 0;
4
- var Predicate_1 = require("effect/Predicate");
5
- var pretty_error_type_1 = require("../../types/pretty-error.type");
6
- var extract_error_details_1 = require("./extract-error-details");
7
- var spanSymbol = Symbol.for('effect/SpanAnnotation');
8
- var parseError = function (error) {
9
- var _a;
10
- var span = (0, Predicate_1.hasProperty)(error, spanSymbol)
11
- ? error[spanSymbol]
12
- : undefined;
13
- var _b = (0, extract_error_details_1.extractErrorDetails)(error), message = _b.message, type = _b.type, isPlainString = _b.isPlainString;
14
- if (error instanceof Error) {
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);
16
- }
17
- return new pretty_error_type_1.PrettyError(message, undefined, span, isPlainString, type);
18
- };
19
- exports.parseError = parseError;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __importDefault = (this && this.__importDefault) || function (mod) {
19
- return (mod && mod.__esModule) ? mod : { "default": mod };
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getSpanAttributes = void 0;
23
- var chalk_1 = __importDefault(require("chalk"));
24
- var split_spans_attributes_by_type_1 = require("./split-spans-attributes-by-type");
25
- var maybePrintPipe = function (isLastEntry) {
26
- return isLastEntry ? ' ' : chalk_1.default.gray('│');
27
- };
28
- var getSpanAttributes = function (allAttributes, isLastEntry) {
29
- if (allAttributes.size === 0) {
30
- return { formattedAttributes: '', stack: [] };
31
- }
32
- var _a = (0, split_spans_attributes_by_type_1.splitSpansAttributesByTypes)(allAttributes), attributes = _a.attributes, stacktrace = _a.stacktrace;
33
- var formattedAttributes = Array.from(attributes)
34
- .map(function (_a) {
35
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
36
- return "".concat(maybePrintPipe(isLastEntry), " ").concat(chalk_1.default.blue(key)).concat(chalk_1.default.gray(':'), " ").concat(value);
37
- })
38
- .join('\r\n');
39
- return {
40
- formattedAttributes: "\r\n".concat(formattedAttributes),
41
- stack: stacktrace,
42
- };
43
- };
44
- exports.getSpanAttributes = getSpanAttributes;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSpanDuration = void 0;
7
- var chalk_1 = __importDefault(require("chalk"));
8
- var getSpanDuration = function (status, isLastEntry) {
9
- if (status._tag !== 'Ended') {
10
- return '';
11
- }
12
- var duration = (status.endTime - status.startTime) / BigInt(1000000);
13
- return "\r\n".concat(isLastEntry ? ' ' : chalk_1.default.gray('│'), " ~ ").concat(duration, "ms");
14
- };
15
- exports.getSpanDuration = getSpanDuration;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.spanStackTrailingChar = void 0;
7
- var chalk_1 = __importDefault(require("chalk"));
8
- var spanStackTrailingChar = function (isLastEntry) {
9
- return isLastEntry ? chalk_1.default.gray('╰') : chalk_1.default.gray('├');
10
- };
11
- exports.spanStackTrailingChar = spanStackTrailingChar;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.splitSpansAttributesByTypes = void 0;
29
- var splitSpansAttributesByTypes = function (attributes) {
30
- return Array.from(attributes.entries()).reduce(function (prev, _a) {
31
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
32
- if (key === 'code.stacktrace') {
33
- return {
34
- attributes: prev.attributes,
35
- stacktrace: __spreadArray(__spreadArray([], __read(prev.stacktrace), false), [value], false),
36
- };
37
- }
38
- return {
39
- attributes: new Map(__spreadArray(__spreadArray([], __read(prev.attributes), false), [[key, value]], false)),
40
- stacktrace: prev.stacktrace,
41
- };
42
- }, {
43
- stacktrace: [],
44
- attributes: new Map(),
45
- });
46
- };
47
- exports.splitSpansAttributesByTypes = splitSpansAttributesByTypes;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.filterStack = void 0;
15
- var strip_cwd_path_1 = require("../strip-cwd-path");
16
- var filterStack = function (stack, stripCwd) {
17
- var e_1, _a;
18
- var lines = stack.split('\r\n');
19
- var out = [];
20
- try {
21
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
22
- var line = lines_1_1.value;
23
- out.push(line.replace(/at .*effect_cutpoint.*\((.*)\)/, 'at $1'));
24
- if (line.includes('effect_cutpoint')) {
25
- return out.join('\r\n');
26
- }
27
- }
28
- }
29
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30
- finally {
31
- try {
32
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
33
- }
34
- finally { if (e_1) throw e_1.error; }
35
- }
36
- var final = out.join('\r\n').replace(/ {4}at /g, '│ at ');
37
- return stripCwd ? (0, strip_cwd_path_1.stripCwdPath)(final) : final;
38
- };
39
- exports.filterStack = filterStack;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripCwdPath = void 0;
4
- var cwdRegex = global.process !== undefined ? new RegExp(global.process.cwd(), 'g') : null;
5
- var stripCwdPath = function (path) {
6
- return cwdRegex === null ? path : path.replace(cwdRegex, '.');
7
- };
8
- exports.stripCwdPath = stripCwdPath;
package/pretty-print.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { type Cause } from 'effect/Cause';
2
- import { type PrettyPrintOptions } from './types/pretty-print-options.type';
3
- export declare const prettyPrint: <E>(cause: Cause<E>, { stripCwd, reverseSpans }?: PrettyPrintOptions) => string;
package/pretty-print.js DELETED
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- var __importDefault = (this && this.__importDefault) || function (mod) {
28
- return (mod && mod.__esModule) ? mod : { "default": mod };
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.prettyPrint = void 0;
32
- var chalk_1 = __importDefault(require("chalk"));
33
- var effect_1 = require("effect");
34
- var Cause_1 = require("effect/Cause");
35
- var capture_errors_from_cause_1 = require("./logic/errors/capture-errors-from-cause");
36
- var get_span_attributes_1 = require("./logic/spans/get-span-attributes");
37
- var get_span_duration_1 = require("./logic/spans/get-span-duration");
38
- var spans_stack_trailing_char_1 = require("./logic/spans/spans-stack-trailing-char");
39
- var filter_stack_1 = require("./logic/stack/filter-stack");
40
- var strip_cwd_path_1 = require("./logic/strip-cwd-path");
41
- var pretty_print_options_type_1 = require("./types/pretty-print-options.type");
42
- var prettyPrint = function (cause, _a) {
43
- var _b = _a === void 0 ? pretty_print_options_type_1.prettyPrintOptionsDefault : _a, stripCwd = _b.stripCwd, reverseSpans = _b.reverseSpans;
44
- if ((0, Cause_1.isInterruptedOnly)(cause)) {
45
- return 'All fibers interrupted without errors.';
46
- }
47
- var failures = (0, capture_errors_from_cause_1.captureErrorsFrom)(cause);
48
- console.error("\r\n\uD83E\uDEE0 ".concat(chalk_1.default.bold.yellowBright.underline("".concat(failures.length, " error").concat(failures.length > 1 ? 's' : '', " occured\r\n"))));
49
- return failures
50
- .map(function (_a, failuresIndex) {
51
- var _b;
52
- var errorType = _a.errorType, errorMessage = _a.message, stack = _a.stack, span = _a.span, isPlainString = _a.isPlainString;
53
- var message = '💥 ' +
54
- (failures.length > 1
55
- ? chalk_1.default.bgRed.whiteBright(" #".concat(failuresIndex + 1, " -"))
56
- : '') +
57
- chalk_1.default.bgRed.whiteBright(" ".concat((_b = errorType) !== null && _b !== void 0 ? _b : 'Unknown error', " ")) +
58
- chalk_1.default.bold.whiteBright(" \u2022 ".concat(errorMessage)) +
59
- '\r\n';
60
- if (isPlainString) {
61
- 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.'));
62
- }
63
- var spanAttributesStack = [];
64
- if (span !== undefined) {
65
- var current = span;
66
- var spans_1 = [];
67
- while (current !== undefined && current._tag === 'Span') {
68
- spans_1.push(current);
69
- current = effect_1.Option.getOrUndefined(current.parent);
70
- }
71
- var orderedSpans = reverseSpans === true ? spans_1.toReversed() : spans_1;
72
- message += orderedSpans
73
- .map(function (_a, index) {
74
- var name = _a.name, attributes = _a.attributes, status = _a.status;
75
- var isFirstEntry = index === 0;
76
- var isLastEntry = index === spans_1.length - 1;
77
- var filePath = " at ".concat(stripCwd !== undefined ? (0, strip_cwd_path_1.stripCwdPath)(name) : name);
78
- var _b = (0, get_span_attributes_1.getSpanAttributes)(attributes, isLastEntry), formattedAttributes = _b.formattedAttributes, stack = _b.stack;
79
- spanAttributesStack.push.apply(spanAttributesStack, __spreadArray([], __read(stack), false));
80
- return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
81
- '\r\n' +
82
- (0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
83
- chalk_1.default.gray('─') +
84
- filePath +
85
- (0, get_span_duration_1.getSpanDuration)(status, isLastEntry) +
86
- formattedAttributes);
87
- })
88
- .join('');
89
- }
90
- else if (!isPlainString) {
91
- message += "\r\n".concat(chalk_1.default.gray('ℹ️ Consider using spans to improve errors reporting.\r\n'));
92
- }
93
- if (spanAttributesStack.length > 0) {
94
- var cleanedStack = "\u2502 ".concat((0, filter_stack_1.filterStack)(spanAttributesStack.join('\r\n│ '), stripCwd === true));
95
- message += "\r\n\uD83D\uDEA8 Effect Stacktrace\r\n".concat(chalk_1.default.red(cleanedStack));
96
- }
97
- if (stack !== undefined) {
98
- message += "\r\n".concat(span !== undefined ? '\r\n' : '', "\uD83D\uDEA8 Node Stacktrace\r\n").concat(chalk_1.default.red((0, filter_stack_1.filterStack)(stack, stripCwd === true)));
99
- }
100
- else if (!isPlainString) {
101
- 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.'));
102
- }
103
- return message + '\r\n';
104
- })
105
- .join('\r\n');
106
- };
107
- exports.prettyPrint = prettyPrint;
@@ -1,89 +0,0 @@
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
- };
63
- Object.defineProperty(exports, "__esModule", { value: true });
64
- exports.runPromise = void 0;
65
- var effect_1 = require("effect");
66
- var __1 = require("..");
67
- var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
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
- });
88
- };
89
- exports.runPromise = runPromise;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runSync = void 0;
4
- var effect_1 = require("effect");
5
- var __1 = require("..");
6
- var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
7
- var runSync = function (effect, options) {
8
- if (options === void 0) { options = pretty_print_options_type_1.prettyPrintOptionsDefault; }
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 === true) {
11
- console.error((0, __1.prettyPrint)(e, options));
12
- return effect_1.Effect.fail('❌ runSync failure');
13
- }
14
- return effect_1.Effect.fail(e);
15
- })));
16
- };
17
- exports.runSync = runSync;
@@ -1,9 +0,0 @@
1
- import { type Mock } from 'vitest';
2
- interface ConsoleMockingArgs {
3
- error?: Mock;
4
- info?: Mock;
5
- log?: Mock;
6
- warn?: Mock;
7
- }
8
- export declare const mockConsole: (args: ConsoleMockingArgs) => Promise<void>;
9
- export {};
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.mockConsole = void 0;
51
- var vitest_1 = require("vitest");
52
- var mockConsole = function (args) { return __awaiter(void 0, void 0, void 0, function () {
53
- var _a, _b;
54
- return __generator(this, function (_c) {
55
- switch (_c.label) {
56
- case 0:
57
- _a = global;
58
- _b = [{}];
59
- return [4 /*yield*/, vitest_1.vi.importActual('node:console')];
60
- case 1:
61
- _a.console = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_c.sent())])), args]);
62
- return [2 /*return*/];
63
- }
64
- });
65
- }); };
66
- exports.mockConsole = mockConsole;
@@ -1,2 +0,0 @@
1
- import { Effect } from 'effect';
2
- export declare const effectCause: <A, E>(effect: Effect.Effect<A, E>) => Promise<import("effect/Cause").Cause<E>>;
@@ -1,49 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.effectCause = void 0;
40
- var effect_1 = require("effect");
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
- }); };
49
- exports.effectCause = effectCause;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrettyError = void 0;
4
- var PrettyError = /** @class */ (function () {
5
- function PrettyError(message, stack, span, isPlainString, errorType) {
6
- this.message = message;
7
- this.stack = stack;
8
- this.span = span;
9
- this.isPlainString = isPlainString;
10
- this.errorType = errorType;
11
- }
12
- return PrettyError;
13
- }());
14
- exports.PrettyError = PrettyError;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prettyPrintOptionsDefault = void 0;
4
- exports.prettyPrintOptionsDefault = {
5
- enabled: true,
6
- stripCwd: false,
7
- reverseSpans: true,
8
- };