effect-errors 1.2.24 → 1.3.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.
Files changed (41) hide show
  1. package/README.md +44 -0
  2. package/capture-errors.d.ts +19 -0
  3. package/capture-errors.js +42 -0
  4. package/caputre-errors.test.d.ts +1 -0
  5. package/caputre-errors.test.js +156 -0
  6. package/examples/errors/fetch-error.d.ts +9 -0
  7. package/examples/errors/fetch-error.js +27 -0
  8. package/examples/errors/file-error.d.ts +9 -0
  9. package/examples/errors/file-error.js +27 -0
  10. package/examples/errors/user-not-found.error.d.ts +9 -0
  11. package/examples/errors/user-not-found.error.js +27 -0
  12. package/examples/from-promise.d.ts +5 -0
  13. package/examples/from-promise.js +113 -0
  14. package/examples/parallel-errors.d.ts +4 -0
  15. package/examples/parallel-errors.js +69 -0
  16. package/examples/util/filename.effect.d.ts +2 -0
  17. package/examples/util/filename.effect.js +11 -0
  18. package/index.d.ts +1 -0
  19. package/index.js +1 -0
  20. package/logic/errors/capture-errors-from-cause.d.ts +2 -2
  21. package/logic/errors/capture-errors-from-cause.js +1 -1
  22. package/logic/errors/extract-error-details.d.ts +7 -0
  23. package/logic/errors/extract-error-details.js +74 -0
  24. package/logic/errors/parse-error.js +7 -4
  25. package/logic/spans/get-span-duration.d.ts +1 -1
  26. package/logic/strip-cwd-path.js +1 -1
  27. package/package.json +21 -13
  28. package/pretty-print.d.ts +2 -2
  29. package/pretty-print.js +38 -27
  30. package/runners/run-promise.d.ts +1 -1
  31. package/runners/run-promise.js +81 -9
  32. package/runners/run-sync.d.ts +1 -1
  33. package/runners/run-sync.js +1 -1
  34. package/tests/mocks/console.mock.d.ts +9 -0
  35. package/tests/mocks/console.mock.js +66 -0
  36. package/tests/runners/effect-cause.d.ts +2 -0
  37. package/tests/runners/effect-cause.js +49 -0
  38. package/types/pretty-error.type.d.ts +5 -10
  39. package/types/pretty-error.type.js +3 -11
  40. package/logic/errors/pretty-error-message.d.ts +0 -1
  41. package/logic/errors/pretty-error-message.js +0 -59
@@ -0,0 +1,74 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.extractErrorDetails = void 0;
20
+ var Function_1 = require("effect/Function");
21
+ var Predicate_1 = require("effect/Predicate");
22
+ var extractErrorDetails = function (error) {
23
+ if (typeof error === 'string') {
24
+ return {
25
+ isPlainString: true,
26
+ message: error,
27
+ };
28
+ }
29
+ // TaggedError with cause
30
+ if (error instanceof Error &&
31
+ (0, Predicate_1.hasProperty)(error, 'cause') &&
32
+ (0, Predicate_1.hasProperty)(error, '_tag')) {
33
+ return {
34
+ isPlainString: false,
35
+ type: error._tag,
36
+ message: error.cause,
37
+ };
38
+ }
39
+ // TaggedError with error ctor
40
+ if (error instanceof Error && (0, Predicate_1.hasProperty)(error, 'error')) {
41
+ return {
42
+ isPlainString: false,
43
+ type: error.name,
44
+ message: error.error,
45
+ };
46
+ }
47
+ // Plain objects with tag attribute
48
+ if ((0, Predicate_1.hasProperty)(error, '_tag') && (0, Predicate_1.hasProperty)(error, 'message')) {
49
+ return {
50
+ isPlainString: false,
51
+ type: error._tag,
52
+ message: error.message,
53
+ };
54
+ }
55
+ // Plain objects with toString impl
56
+ if ((0, Predicate_1.hasProperty)(error, 'toString') &&
57
+ (0, Function_1.isFunction)(error.toString) &&
58
+ error.toString !== Object.prototype.toString &&
59
+ error.toString !== Array.prototype.toString) {
60
+ var message = error.toString();
61
+ var maybeWithUnderlyingType = message.split(': ');
62
+ if (maybeWithUnderlyingType.length > 1) {
63
+ var _a = __read(maybeWithUnderlyingType), type = _a[0], message_1 = _a.slice(1);
64
+ return {
65
+ isPlainString: false,
66
+ type: type,
67
+ message: message_1,
68
+ };
69
+ }
70
+ return { message: message, isPlainString: false };
71
+ }
72
+ return { message: "Error: ".concat(JSON.stringify(error)), isPlainString: false };
73
+ };
74
+ exports.extractErrorDetails = extractErrorDetails;
@@ -3,14 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseError = void 0;
4
4
  var Predicate_1 = require("effect/Predicate");
5
5
  var pretty_error_type_1 = require("../../types/pretty-error.type");
6
- var pretty_error_message_1 = require("./pretty-error-message");
6
+ var extract_error_details_1 = require("./extract-error-details");
7
7
  var spanSymbol = Symbol.for('effect/SpanAnnotation');
8
8
  var parseError = function (error) {
9
9
  var _a;
10
- var span = ((0, Predicate_1.hasProperty)(error, spanSymbol) && error[spanSymbol]);
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;
11
14
  if (error instanceof Error) {
12
- return new pretty_error_type_1.PrettyError((0, pretty_error_message_1.prettyErrorMessage)(error), (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n').filter(function (el) { return /at (.*)/.exec(el); }).join('\r\n'), span);
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);
13
16
  }
14
- return new pretty_error_type_1.PrettyError((0, pretty_error_message_1.prettyErrorMessage)(error), void 0, span);
17
+ return new pretty_error_type_1.PrettyError(message, undefined, span, isPlainString, type);
15
18
  };
16
19
  exports.parseError = parseError;
@@ -1,2 +1,2 @@
1
- import { SpanStatus } from 'effect/Tracer';
1
+ import { type SpanStatus } from 'effect/Tracer';
2
2
  export declare const getSpanDuration: (status: SpanStatus, isLastEntry: boolean) => string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripCwdPath = void 0;
4
- var cwdRegex = global.process ? new RegExp(global.process.cwd(), 'g') : null;
4
+ var cwdRegex = global.process !== undefined ? new RegExp(global.process.cwd(), 'g') : null;
5
5
  var stripCwdPath = function (path) {
6
6
  return cwdRegex === null ? path : path.replace(cwdRegex, '.');
7
7
  };
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.2.24",
5
+ "version": "1.3.1",
6
6
  "author": "jpb06 <jp.bois.06@outlook.fr>",
7
7
  "description": "A POC for errors reporting in Effect",
8
8
  "keywords": [],
@@ -27,32 +27,40 @@
27
27
  "run-examples": "bun run ./src/examples/util/run-all"
28
28
  },
29
29
  "dependencies": {
30
- "@effect/schema": "^0.64.11",
30
+ "@effect/schema": "^0.66.5",
31
31
  "chalk": "<5",
32
- "effect": "^2.4.11"
32
+ "effect": "^3.0.3"
33
33
  },
34
34
  "devDependencies": {
35
- "@stylistic/eslint-plugin": "^1.7.0",
36
- "@types/eslint": "^8.56.6",
35
+ "@eslint/eslintrc": "^3.0.2",
36
+ "@eslint/js": "^9.1.1",
37
+ "@stylistic/eslint-plugin": "^1.7.2",
38
+ "@stylistic/eslint-plugin-ts": "^1.7.2",
39
+ "@types/eslint": "^8.56.10",
37
40
  "@types/fs-extra": "^11.0.4",
38
- "@types/node": "^20.11.30",
39
- "@typescript-eslint/eslint-plugin": "^7.3.1",
40
- "@typescript-eslint/parser": "^7.3.1",
41
- "@vitest/coverage-v8": "^1.4.0",
41
+ "@types/node": "^20.12.7",
42
+ "@typescript-eslint/eslint-plugin": "^7.7.0",
43
+ "@typescript-eslint/parser": "^7.7.0",
44
+ "@vitest/coverage-v8": "^1.5.0",
42
45
  "copyfiles": "^2.4.1",
43
46
  "del-cli": "^5.1.0",
44
- "eslint": "^8.57.0",
47
+ "eslint": "^9.1.0",
45
48
  "eslint-config-prettier": "^9.1.0",
49
+ "eslint-config-standard-with-typescript": "^43.0.1",
46
50
  "eslint-import-resolver-typescript": "^3.6.1",
47
51
  "eslint-plugin-import": "^2.29.1",
48
52
  "eslint-plugin-markdown": "^4.0.1",
53
+ "eslint-plugin-n": "^17.2.1",
49
54
  "eslint-plugin-prettier": "^5.1.3",
50
- "eslint-plugin-vitest": "^0.3.26",
55
+ "eslint-plugin-promise": "^6.1.1",
56
+ "eslint-plugin-vitest": "^0.5.3",
51
57
  "fs-extra": "^11.2.0",
58
+ "globals": "^15.0.0",
52
59
  "prettier": "^3.2.5",
53
60
  "readme-package-icons": "^1.1.14",
54
- "typescript": "^5.4.3",
55
- "vitest": "^1.4.0",
61
+ "typescript": "*",
62
+ "typescript-eslint": "^7.7.0",
63
+ "vitest": "^1.5.0",
56
64
  "vitest-mock-extended": "^1.3.1"
57
65
  }
58
66
  }
package/pretty-print.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Cause } from 'effect/Cause';
2
- import { PrettyPrintOptions } from './types/pretty-print-options.type';
1
+ import { type Cause } from 'effect/Cause';
2
+ import { type PrettyPrintOptions } from './types/pretty-print-options.type';
3
3
  export declare const prettyPrint: <E>(cause: Cause<E>, { stripCwd }?: PrettyPrintOptions) => string;
package/pretty-print.js CHANGED
@@ -23,39 +23,50 @@ var prettyPrint = function (cause, _a) {
23
23
  console.error("\r\n\uD83E\uDEE0 ".concat(chalk_1.default.bold.yellowBright.underline("".concat(failures.length, " error").concat(failures.length > 1 ? 's' : '', " occurred\r\n"))));
24
24
  return failures
25
25
  .map(function (_a, failuresIndex) {
26
- var message = _a.message, stack = _a.stack, span = _a.span;
27
- if (span) {
26
+ var _b;
27
+ var errorType = _a.errorType, errorMessage = _a.message, stack = _a.stack, span = _a.span, isPlainString = _a.isPlainString;
28
+ var message = '💥 ' +
29
+ (failures.length > 1
30
+ ? chalk_1.default.bgRed.whiteBright(" #".concat(failuresIndex + 1, " -"))
31
+ : '') +
32
+ chalk_1.default.bgRed.whiteBright(" ".concat((_b = errorType) !== null && _b !== void 0 ? _b : 'Unknown error', " ")) +
33
+ chalk_1.default.bold.whiteBright(" \u2022 ".concat(errorMessage)) +
34
+ '\r\n';
35
+ if (isPlainString) {
36
+ 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.'));
37
+ }
38
+ if (span !== undefined) {
28
39
  var current = span;
29
40
  var spans_1 = [];
30
- while (current && current._tag === 'Span') {
41
+ while (current !== undefined && current._tag === 'Span') {
31
42
  spans_1.push(current);
32
43
  current = effect_1.Option.getOrUndefined(current.parent);
33
44
  }
34
- message =
35
- '💥 ' +
36
- (failures.length > 1
37
- ? chalk_1.default.bgRed.whiteBright(" #".concat(failuresIndex + 1, " -"))
38
- : '') +
39
- message +
40
- spans_1
41
- .toReversed()
42
- .map(function (_a, index) {
43
- var name = _a.name, attributes = _a.attributes, status = _a.status;
44
- var isFirstEntry = index === 0;
45
- var isLastEntry = index === spans_1.length - 1;
46
- var filePath = " at ".concat(stripCwd ? (0, strip_cwd_path_1.stripCwdPath)(name) : name);
47
- return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
48
- '\r\n' +
49
- (0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
50
- chalk_1.default.gray('─') +
51
- filePath +
52
- (0, get_span_duration_1.getSpanDuration)(status, isLastEntry) +
53
- (0, get_span_attributes_1.getSpanAttributes)(attributes, isLastEntry));
54
- })
55
- .join('');
45
+ message += spans_1
46
+ .toReversed()
47
+ .map(function (_a, index) {
48
+ var name = _a.name, attributes = _a.attributes, status = _a.status;
49
+ var isFirstEntry = index === 0;
50
+ var isLastEntry = index === spans_1.length - 1;
51
+ var filePath = " at ".concat(stripCwd !== undefined ? (0, strip_cwd_path_1.stripCwdPath)(name) : name);
52
+ return chalk_1.default.whiteBright((isFirstEntry ? "\r\n".concat(chalk_1.default.gray('◯')) : '') +
53
+ '\r\n' +
54
+ (0, spans_stack_trailing_char_1.spanStackTrailingChar)(isLastEntry) +
55
+ chalk_1.default.gray('─') +
56
+ filePath +
57
+ (0, get_span_duration_1.getSpanDuration)(status, isLastEntry) +
58
+ (0, get_span_attributes_1.getSpanAttributes)(attributes, isLastEntry));
59
+ })
60
+ .join('');
61
+ }
62
+ else if (!isPlainString) {
63
+ message += "\r\n".concat(chalk_1.default.gray('ℹ️ Consider using spans to improve errors reporting.\r\n'));
64
+ }
65
+ if (stack !== undefined) {
66
+ message += "\r\n".concat(span !== undefined ? '\r\n' : '', "\uD83D\uDEA8 Stacktrace\r\n").concat(chalk_1.default.red((0, filter_stack_1.filterStack)(stack, stripCwd === true)));
56
67
  }
57
- if (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 === true)));
68
+ else if (!isPlainString) {
69
+ 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.'));
59
70
  }
60
71
  return message + '\r\n';
61
72
  })
@@ -1,3 +1,3 @@
1
1
  import { Effect } from 'effect';
2
- import { PrettyPrintOptions } from '../types/pretty-print-options.type';
2
+ import { type PrettyPrintOptions } from '../types/pretty-print-options.type';
3
3
  export declare const runPromise: <A, E>(effect: Effect.Effect<A, E>, options?: PrettyPrintOptions) => Promise<A>;
@@ -1,17 +1,89 @@
1
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
+ };
2
63
  Object.defineProperty(exports, "__esModule", { value: true });
3
64
  exports.runPromise = void 0;
4
65
  var effect_1 = require("effect");
5
66
  var __1 = require("..");
6
67
  var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
7
- var runPromise = function (effect, options) {
8
- if (options === void 0) { options = pretty_print_options_type_1.prettyPrintOptionsDefault; }
9
- return effect_1.Effect.runPromise((0, effect_1.pipe)(effect, effect_1.Effect.sandbox, effect_1.Effect.catchAll(function (e) {
10
- if (options.enabled === false) {
11
- return effect_1.Effect.fail(e);
12
- }
13
- console.error((0, __1.prettyPrint)(e, options));
14
- return effect_1.Effect.fail('❌ runPromise failure');
15
- })));
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
+ });
16
88
  };
17
89
  exports.runPromise = runPromise;
@@ -1,3 +1,3 @@
1
1
  import { Effect } from 'effect';
2
- import { PrettyPrintOptions } from '../types/pretty-print-options.type';
2
+ import { type PrettyPrintOptions } from '../types/pretty-print-options.type';
3
3
  export declare const runSync: <A, E>(effect: Effect.Effect<A, E>, options?: PrettyPrintOptions) => A;
@@ -7,7 +7,7 @@ var pretty_print_options_type_1 = require("../types/pretty-print-options.type");
7
7
  var runSync = function (effect, options) {
8
8
  if (options === void 0) { options = pretty_print_options_type_1.prettyPrintOptionsDefault; }
9
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) {
10
+ if (options.enabled === true) {
11
11
  console.error((0, __1.prettyPrint)(e, options));
12
12
  return effect_1.Effect.fail('❌ runSync failure');
13
13
  }
@@ -0,0 +1,9 @@
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 {};
@@ -0,0 +1,66 @@
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;
@@ -0,0 +1,2 @@
1
+ import { Effect } from 'effect';
2
+ export declare const effectCause: <A, E>(effect: Effect.Effect<A, E>) => Promise<import("effect/Cause").Cause<E>>;
@@ -0,0 +1,49 @@
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 +1,9 @@
1
- import { Span } from 'effect/Tracer';
2
- interface Error {
3
- message: string;
4
- stack?: string;
5
- span?: Span;
6
- }
1
+ import { type Span } from 'effect/Tracer';
7
2
  export declare class PrettyError {
8
- readonly message: string;
3
+ readonly message: unknown;
9
4
  readonly stack: string | undefined;
10
5
  readonly span: Span | undefined;
11
- constructor(message: string, stack: string | undefined, span: Span | undefined);
12
- toJSON(): Error;
6
+ readonly isPlainString: boolean;
7
+ readonly errorType?: unknown;
8
+ constructor(message: unknown, stack: string | undefined, span: Span | undefined, isPlainString: boolean, errorType?: unknown);
13
9
  }
14
- export {};
@@ -2,21 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PrettyError = void 0;
4
4
  var PrettyError = /** @class */ (function () {
5
- function PrettyError(message, stack, span) {
5
+ function PrettyError(message, stack, span, isPlainString, errorType) {
6
6
  this.message = message;
7
7
  this.stack = stack;
8
8
  this.span = span;
9
+ this.isPlainString = isPlainString;
10
+ this.errorType = errorType;
9
11
  }
10
- PrettyError.prototype.toJSON = function () {
11
- var out = { message: this.message };
12
- if (this.stack) {
13
- out.stack = this.stack;
14
- }
15
- if (this.span) {
16
- out.span = this.span;
17
- }
18
- return out;
19
- };
20
12
  return PrettyError;
21
13
  }());
22
14
  exports.PrettyError = PrettyError;
@@ -1 +0,0 @@
1
- export declare const prettyErrorMessage: (u: unknown) => string;
@@ -1,59 +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.prettyErrorMessage = void 0;
23
- var chalk_1 = __importDefault(require("chalk"));
24
- var Function_1 = require("effect/Function");
25
- var Predicate_1 = require("effect/Predicate");
26
- var redBackground = function (text) { return chalk_1.default.bgRed(" ".concat(text, " ")); };
27
- var whiteBright = function (text) { return chalk_1.default.bold.whiteBright("\u2022 ".concat(text)); };
28
- var prettyErrorMessage = function (u) {
29
- if (typeof u === 'string') {
30
- 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.'));
31
- }
32
- // TaggedError with cause
33
- if (u instanceof Error && (0, Predicate_1.hasProperty)(u, 'cause') && (0, Predicate_1.hasProperty)(u, '_tag')) {
34
- return "".concat(redBackground(u._tag), " ").concat(whiteBright(u.cause), "\r\n");
35
- }
36
- // TaggedError with error ctor
37
- if (u instanceof Error && (0, Predicate_1.hasProperty)(u, 'error')) {
38
- return "".concat(redBackground(u.name), " ").concat(whiteBright(u.error), "\r\n");
39
- }
40
- // Plain objects with tag attribute
41
- if ((0, Predicate_1.hasProperty)(u, '_tag') && (0, Predicate_1.hasProperty)(u, 'message')) {
42
- return "".concat(redBackground(u._tag), " ").concat(whiteBright(u.message), "\r\n");
43
- }
44
- // Plain objects with toString impl
45
- if ((0, Predicate_1.hasProperty)(u, 'toString') &&
46
- (0, Function_1.isFunction)(u['toString']) &&
47
- u['toString'] !== Object.prototype.toString &&
48
- u['toString'] !== Array.prototype.toString) {
49
- var message = u['toString']();
50
- var maybeWithUnderlyingType = message.split(': ');
51
- if (maybeWithUnderlyingType.length > 1) {
52
- var _a = __read(maybeWithUnderlyingType), type = _a[0], message_1 = _a.slice(1);
53
- return "".concat(redBackground(type), " ").concat(whiteBright(message_1));
54
- }
55
- return "".concat(message);
56
- }
57
- return "Error: ".concat(JSON.stringify(u));
58
- };
59
- exports.prettyErrorMessage = prettyErrorMessage;