effect-errors 1.0.9 → 1.1.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
@@ -95,6 +95,14 @@ Effect.tryPromise({
95
95
  Effect.fail(new UserNotFoundError({ cause: "User does not exist" }));
96
96
  ```
97
97
 
98
+ ### 🔶 Plain object
99
+
100
+ Alternativly, you _can_ use a plain object with a `_tag` and `message` attribute:
101
+
102
+ ```typescript
103
+ Effect.fail({ _tag: 'SucksToBeMe', message: 'Yeah...' });
104
+ ```
105
+
98
106
  ## ⚡ examples
99
107
 
100
108
  I wrote some examples for fun and giggles. You can run them using:
@@ -25,7 +25,7 @@ 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);
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.'));
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')) {
@@ -35,6 +35,10 @@ var prettyErrorMessage = function (u) {
35
35
  if (u instanceof Error && (0, Predicate_1.hasProperty)(u, 'error')) {
36
36
  return "\uD83D\uDCA5 ".concat(chalk_1.default.bgRed(" ".concat(u.name, " ")), " ").concat(chalk_1.default.bold.whiteBright("\u2022 ".concat(u.error)), "\r\n");
37
37
  }
38
+ // Plain objects with tag attribute
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");
41
+ }
38
42
  if ((0, Predicate_1.hasProperty)(u, 'toString') &&
39
43
  (0, Function_1.isFunction)(u['toString']) &&
40
44
  u['toString'] !== Object.prototype.toString &&
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.0.9",
5
+ "version": "1.1.1",
6
6
  "author": "jpb06 <jp.bois.06@outlook.fr>",
7
7
  "description": "A POC for errors reporting in Effect",
8
8
  "keywords": [],
@@ -31,7 +31,7 @@
31
31
  "@stylistic/eslint-plugin": "^1.6.3",
32
32
  "@types/eslint": "^8.56.5",
33
33
  "@types/fs-extra": "^11.0.4",
34
- "@types/node": "^20.11.24",
34
+ "@types/node": "^20.11.25",
35
35
  "@typescript-eslint/eslint-plugin": "^7.1.1",
36
36
  "@typescript-eslint/parser": "^7.1.1",
37
37
  "copyfiles": "^2.4.1",
@@ -45,6 +45,6 @@
45
45
  "fs-extra": "^11.2.0",
46
46
  "prettier": "^3.2.5",
47
47
  "readme-package-icons": "^1.1.14",
48
- "typescript": "^5.0.0"
48
+ "typescript": "^5.4.2"
49
49
  }
50
50
  }
@@ -1,2 +1,2 @@
1
1
  import { Effect } from 'effect';
2
- export declare const runPromise: <A, E>(effect: Effect.Effect<A, E, never>) => Promise<A>;
2
+ export declare const runPromise: <A, E>(effect: Effect.Effect<A, E>) => Promise<A>;
@@ -1,2 +1,2 @@
1
1
  import { Effect } from 'effect';
2
- export declare const runSync: <A, E>(effect: Effect.Effect<A, E, never>) => A;
2
+ export declare const runSync: <A, E>(effect: Effect.Effect<A, E>) => A;