immediate-error 12.2.0 → 12.2.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.
package/LICENCE ADDED
@@ -0,0 +1,30 @@
1
+ Enterprise General Public Software License 10x
2
+ Version 1.0 (EGPSL10X-1.0)
3
+
4
+ Copyright (c) 2025 10x'ly Made Software Ventures AB
5
+
6
+ This license is a guide on your rights to use the Software, redistribute the Software, and any other rights pertaining/related to the Software. Read this entire license carefully before using the Software.
7
+ This license is in the public domain.
8
+
9
+ Definitions:
10
+
11
+ 1. The "License" or "license" is this text laying out the terms and conditions of the Software.
12
+ 2. The "Software" is the software that you are currently using that uses this license.
13
+
14
+ Terms:
15
+
16
+ 1. the User can do absolutely whatever they want with the Software.
17
+ 2. Additional terms: the creator of the Software is not responsible for anything that may happen to you that resulted from the use of the Software, which includes, but is not limited to: death, endless crying, laughing, embarassment, over-seriousness, under-seriousness, bloating, cancer, tuberculosis, addiction, war crimes, criminal acts, human trafficking, homocide, physical injury, disease, overdose, ligma, arthiritis, ect. It's not Their Problem.
18
+ 3. To the fullest extent permitted by law, the creator(s) of this work dedicate all copyright and related rights in this work to the public domain worldwide, EXCEPT, depending on the Schrodinger state of the universe, certain individuals who have ever read or viewed any portion of this license text, including the notice above, if the superposition collapses right.
19
+
20
+ Other Notes:
21
+
22
+ 1. If anything is vague in this license, you can add your own details to the License. After all, just do whatever you want.
23
+
24
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ BY USING THIS SOFTWARE, YOU AGREE THAT ANY ARGUMENTS RELATED TO THE SOFTWARE HAVE AN ASSUMPTION THAT YOU HAVE READ THIS ENTIRE LICENSE. TO AVOID LEGAL CONFLICTS, PLEASE READ THE ENTIRETY OF THIS LICENSE, OR DON'T, BUT AT YOUR OWN RISK.
27
+
28
+ IF YOU DO NOT WANT TO READ THIS WHOLE LICENSE, ALL YOU NEED TO READ IS ON THE LAST LINE OF THIS FILE.
29
+
30
+ Do whatever you want with the Software.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `immediate-error`
2
2
 
3
- General error-related utility library. 10x Engineered. It's for: throwing errors, getting cached error intrinsics, and try-cach alternative functional handling.
3
+ General error-related utility library. 10x Engineered. It's for: throwing errors, getting catched error intrinsics, and try-cach alternative functional handling.
4
4
 
5
5
  ## Installation
6
6
  ```bash
@@ -40,6 +40,8 @@ immediateError("person not hungry error", ErrorType.PersonNotHungryError) // thr
40
40
 
41
41
  immediateError("portions error", ErrorType.PortionsError) // throws a PortionsError
42
42
 
43
+ immediateError("falsejs validation failed to pass error", ErrorType.FalseJSValidationFailedToPassError) // throws a FalseJSValidationFailedToPassError
44
+
43
45
  class MyCustomError extends Error {
44
46
  constructor (message) {
45
47
  super("Custom: " + message)
@@ -107,6 +109,7 @@ console.log(MESSAGES.DOMAIN.VEGETABLES_DO_NOT_TALK_ERROR.VEGETABLES_CAN_NOT_TALK
107
109
  console.log(MESSAGES.DOMAIN.PERSON_NOT_HUNGRY_ERROR.IS_NOT_HUNGRY_AND_CANNOT_BE_FED) // "% is not hungry and cannot be fed"
108
110
  console.log(MESSAGES.DOMAIN.PORTIONS_ERROR.PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER) // "Portion size expected to be a positive integer"
109
111
  console.log(MESSAGES.DOMAIN.PORTIONS_ERROR.TOO_MANY_PORTIONS) // "Too many portions"
112
+ console.log(MESSAGES.DOMAIN.FALSEJS_VALIDATION_FAILED_TO_PASS_ERROR.VALIDATION_FAILED_TO_PASS) // "Validation failed to pass"
110
113
  ```
111
114
 
112
115
  ## `immediate-error` 2.0.0
@@ -127,6 +130,25 @@ throwErrorWithMessage("Test") // throws an error with message Test
127
130
 
128
131
  It always throws a base error with the message passed in.
129
132
 
130
-
131
133
  ## License
132
- Unlicense
134
+ [EGPSL10X-1.0](https://github.com/10xly/licence)
135
+
136
+ ## Code Of Conduct
137
+ [10xly Lolite Code Of Conduct](https://github.com/10xly/lolite/blob/main/CODE_OF_CONDUCT.md)
138
+
139
+ ## Legal
140
+ [Legal](https://github.com/10xly/legal)
141
+
142
+ ## One thing
143
+
144
+ While your wasting your valuable time using this very useful package, I'd like to make some things clear:
145
+
146
+ People are actually vegetables, and vegetables are actually fruits. Vegetables can't talk but people can, and vegetables can turn into guacamole. You can't eat guacamole, you can only specify its portions.
147
+
148
+ Sources:
149
+ - [libperson](https://npmjs.com/package/libperson?activeTab=code)
150
+ - [libvegetable](https://npmjs.com/package/libvegetable?activeTab=code)
151
+ - [jsfruit](https://npmjs.com/package/jsfruit?activeTab=code)
152
+ - [libguacamole](https://npmjs.com/package/libguacamole?activeTab=code)
153
+
154
+ These packages are by [skibidi-toilet-hacker](https://npmjs.com/~skibidi-toilet-hacker) a legendary 10x developer.
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // type definitions
1
2
  export enum ErrorType {
2
3
  BaseError = 0,
3
4
  EvalError = 1,
@@ -10,6 +11,7 @@ export enum ErrorType {
10
11
  VegetablesDoNotTalkError = 8,
11
12
  PersonNotHungryError = 9,
12
13
  PortionsError = 10,
14
+ FalseJSValidationFailedToPassError = 11
13
15
  }
14
16
  export type CustomError = {
15
17
  new (message: string): Error
@@ -31,6 +33,7 @@ export function getError(
31
33
  ): CustomError
32
34
  export function getError(errorType: ErrorType.PersonNotHungryError): CustomError
33
35
  export function getError(errorType: ErrorType.PortionsError): CustomError
36
+ export function getError(errorType: ErrorType.FalseJSValidationFailedToPassError): CustomError
34
37
  export function getError(errorType: ErrorType | CustomError): CustomError
35
38
  export function immediateError(
36
39
  message?: string,
@@ -77,6 +80,9 @@ export const MESSAGES: {
77
80
  PORTIONS_ERROR: {
78
81
  PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: "Portion size expected to be a positive integer",
79
82
  TOO_MANY_PORTIONS: "Too many portions"
83
+ },
84
+ FALSEJS_VALIDATION_FAILED_TO_PASS_ERROR: {
85
+ VALIDATION_FAILED_TO_PASS: "Validation failed to pass"
80
86
  }
81
87
  }
82
88
  }
package/index.js CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  // DO NOT FORMAT THIS FILE BECAUSE IT MIGHT BREAK
5
5
 
6
+ require("none")() // performance thing
7
+
6
8
  const GetIntrinsic = require("es-intrinsic-cache")
7
9
  const SimpleCache = require("simple-lru-cache")
8
10
  const Fruit = require("jsfruit")
@@ -112,6 +114,8 @@ const $SyntaxError = require("es-error-intrinsics/SyntaxError")
112
114
  const $TypeError = require("es-error-intrinsics/TypeError")
113
115
  const $URIError = require("es-error-intrinsics/URIError")
114
116
 
117
+ const FalseJSValidationFailedToPassError = require("@falsejs/validation-failed-to-pass-error")
118
+
115
119
  const captureStackTrace = GetIntrinsic("%Error.captureStackTrace%", trueValue())
116
120
 
117
121
  const default_error = concat(E, R, R, O, R, EXCLAMATION_POINT)
@@ -128,6 +132,7 @@ const ErrorType = deepFreeze({
128
132
  VegetablesDoNotTalkError: eight,
129
133
  PersonNotHungryError: nine,
130
134
  PortionsError: ten,
135
+ FalseJSValidationFailedToPassError: eleven
131
136
  })
132
137
 
133
138
  const ErrorMap = construct({
@@ -283,6 +288,8 @@ objGetMember(
283
288
  return result
284
289
  }),
285
290
  )
291
+
292
+ ErrorMap.set(ErrorType.FalseJSValidationFailedToPassError, FalseJSValidationFailedToPassError)
286
293
  })
287
294
 
288
295
  function CreateSleepFunction(delay) {
@@ -397,6 +404,9 @@ exports.MESSAGES = {
397
404
  PORTIONS_ERROR: {
398
405
  PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: portionSizeExpectedToBeAPositiveIntegerMessage,
399
406
  TOO_MANY_PORTIONS: tooManyPortionsMessage
407
+ },
408
+ FALSEJS_VALIDATION_FAILED_TO_PASS_ERROR: {
409
+ VALIDATION_FAILED_TO_PASS: "Validation failed to pass" // use the error message directly as we don't want to install FalseJS because it is really heavy.
400
410
  }
401
411
  }
402
412
  }
package/index.test.js CHANGED
@@ -1,255 +1,265 @@
1
- const {
2
- immediateError,
3
- ErrorType,
4
- throwWhatever,
5
- getError,
6
- MESSAGES
7
- } = require("./index")
8
-
9
- describe("immediateError utility", () => {
10
- test("throws a regular Error with default message when no arguments are passed", () => {
11
- expect(() => immediateError()).toThrow(Error)
12
- expect(() => immediateError()).toThrow("ERROR!")
13
- })
14
-
15
- test("throws a regular Error with a custom message", () => {
16
- expect(() => immediateError("Aaaaah")).toThrow(Error)
17
- expect(() => immediateError("Aaaaah")).toThrow("Aaaaah")
18
- })
19
-
20
- test.each([
21
- ["BaseError", ErrorType.BaseError, Error],
22
- ["EvalError", ErrorType.EvalError, EvalError],
23
- ["RangeError", ErrorType.RangeError, RangeError],
24
- ["ReferenceError", ErrorType.ReferenceError, ReferenceError],
25
- ["SyntaxError", ErrorType.SyntaxError, SyntaxError],
26
- ["TypeError", ErrorType.TypeError, TypeError],
27
- ["URIError", ErrorType.URIError, URIError],
28
- ])("throws % when specified", (name, type, constructor) => {
29
- expect(() => immediateError("test message", type)).toThrow(constructor)
30
- })
31
-
32
- test.each([
33
- ["FruitConsumptionError", ErrorType.FruitConsumptionError],
34
- ["VegetablesDoNotTalkError", ErrorType.VegetablesDoNotTalkError],
35
- ["PersonNotHungryError", ErrorType.PersonNotHungryError],
36
- ["PortionsError", ErrorType.PortionsError],
37
- ])("throws domain-specific % correctly", (name, type) => {
38
- const expectedConstructor = getError(type)
39
- expect(() => immediateError("enterprise failure", type)).toThrow(expectedConstructor)
40
- expect(() => immediateError("enterprise failure", type)).toThrow("enterprise failure")
41
- })
42
-
43
- test("throws a custom user-defined Error class", () => {
44
- class MyCustomError extends Error {
45
- constructor(message) {
46
- super("Custom: " + message)
47
- this.name = "MyCustomError"
48
- }
49
- }
50
-
51
- expect(() => immediateError("Error!", MyCustomError)).toThrow(MyCustomError)
52
- expect(() => immediateError("Error!", MyCustomError)).toThrow(
53
- "Custom: Error!",
54
- )
55
- })
56
-
57
- test("captures stack trace correctly and hides internal frames", () => {
58
- try {
59
- immediateError("stack check")
60
- } catch (error) {
61
- expect(error.stack).not.toMatch(/at immediateError/)
62
- }
63
- })
64
- })
65
-
66
- const { attempt } = require("./index")
67
-
68
- describe("attempt utility", () => {
69
- test("works as a standard function", () => {
70
- let called = false
71
- attempt(() => {
72
- called = true
73
- }).end()
74
- expect(called).toBe(true)
75
- })
76
-
77
- test("works as a constructor returning an instance", () => {
78
- const instance = new attempt(() => {})
79
- expect(instance).toBeDefined()
80
- expect(typeof instance.rescue).toBe("function")
81
- })
82
-
83
- test("triggers rescue when the handler fails", () => {
84
- let errorCaught = false
85
- attempt(() => {
86
- throw new Error("fail")
87
- })
88
- .rescue((e) => {
89
- errorCaught = true
90
- expect(e.message).toBe("fail")
91
- })
92
- .end()
93
- expect(errorCaught).toBe(true)
94
- })
95
-
96
- test("triggers else only when the handler succeeds", () => {
97
- let elseCalled = false
98
- attempt(() => {
99
- return "success"
100
- })
101
- .else(() => {
102
- elseCalled = true
103
- })
104
- .end()
105
- expect(elseCalled).toBe(true)
106
- })
107
-
108
- test("triggers ensure regardless of success or failure", () => {
109
- let counter = 0
110
-
111
- attempt(() => {})
112
- .ensure(() => {
113
- counter++
114
- })
115
- .end()
116
-
117
- attempt(() => {
118
- throw new Error()
119
- })
120
- .rescue(() => {})
121
- .ensure(() => {
122
- counter++
123
- })
124
- .end()
125
-
126
- expect(counter).toBe(2)
127
- })
128
-
129
- test("returns this (the instance) from chaining methods", () => {
130
- const a = attempt(() => {})
131
- const b = a.rescue(() => {})
132
- const c = b.else(() => {})
133
- const d = c.ensure(() => {})
134
-
135
- expect(a).toBe(d)
136
- })
137
- })
138
-
139
- const { delayedError } = require("./index")
140
-
141
- describe("delayedError utility", () => {
142
- const SHORT_DELAY = 10
143
-
144
- test("throws the error after a specified delay", async () => {
145
- const start = Date.now()
146
-
147
- try {
148
- await delayedError("Delayed fail", ErrorType.BaseError, SHORT_DELAY)
149
- } catch (error) {
150
- const duration = Date.now() - start
151
- expect(duration).toBeGreaterThanOrEqual(SHORT_DELAY)
152
- expect(error.message).toBe("Delayed fail")
153
- }
154
- })
155
-
156
- test("uses default error message and type if only delay is provided", async () => {
157
- try {
158
- await delayedError(undefined, undefined, SHORT_DELAY)
159
- } catch (error) {
160
- expect(error.message).toBe("ERROR!")
161
- expect(error).toBeInstanceOf(Error)
162
- }
163
- })
164
-
165
- test("respects custom error types in delayed mode", async () => {
166
- try {
167
- await delayedError("Type fail", ErrorType.TypeError, SHORT_DELAY)
168
- } catch (error) {
169
- expect(error).toBeInstanceOf(TypeError)
170
- expect(error.message).toBe("Type fail")
171
- }
172
- })
173
- })
174
-
175
- describe("throwWhatever utility", () => {
176
- test("throws a standard error object when passed", () => {
177
- const err = new Error("standard fail")
178
- expect(() => throwWhatever(err)).toThrow("standard fail")
179
- })
180
-
181
- test("throws primitive false when passed false", () => {
182
- try {
183
- throwWhatever(false)
184
- } catch (e) {
185
- expect(e).toBe(false)
186
- }
187
- })
188
-
189
- test("throws primitive zero when passed 0", () => {
190
- try {
191
- throwWhatever(0)
192
- } catch (e) {
193
- expect(e).toBe(0)
194
- }
195
- })
196
-
197
- test("throws a string directly when passed a string", () => {
198
- expect(() => throwWhatever("Direct String")).toThrow("Direct String")
199
- })
200
-
201
- test("integrates with getError for custom domain errors", () => {
202
- const FruitError = getError(ErrorType.FruitConsumptionError)
203
- const err = new FruitError("Too many apples")
204
- expect(() => throwWhatever(err)).toThrow(FruitError)
205
- })
206
- })
207
-
208
- describe("getError utility", () => {
209
- test("returns the intrinsic Error constructor for BaseError", () => {
210
- const result = getError(ErrorType.BaseError)
211
- expect(result).toBe(Error)
212
- })
213
-
214
- test("returns the intrinsic TypeError constructor for TypeError", () => {
215
- const result = getError(ErrorType.TypeError)
216
- expect(result).toBe(TypeError)
217
- })
218
-
219
- test("successfully extracts FruitConsumptionError from jsfruit logic", () => {
220
- const FruitError = getError(ErrorType.FruitConsumptionError)
221
- expect(typeof FruitError).toBe("function")
222
- const instance = new FruitError("test")
223
- expect(instance).toBeInstanceOf(Error)
224
- })
225
-
226
- test("successfully extracts PersonNotHungryError from libperson logic", () => {
227
- const HungerError = getError(ErrorType.PersonNotHungryError)
228
- expect(typeof HungerError).toBe("function")
229
- expect(new HungerError()).toBeDefined()
230
- })
231
-
232
- test("successfully extracts PortionsError from libguacamole logic", () => {
233
- const GuacError = getError(ErrorType.PortionsError)
234
- expect(typeof GuacError).toBe("function")
235
- expect(GuacError.name).toBe("PortionsError")
236
- })
237
-
238
- test("returns the same constructor when passed a constructor (identity)", () => {
239
- class MyError extends Error {}
240
- const result = getError(MyError)
241
- expect(result).toBe(MyError)
242
- })
243
- })
244
-
245
- describe("error messages", () => {
246
- test.each([
247
- ["no fruit left", MESSAGES.DOMAIN.FRUIT_CONSUMPTION_ERROR.NO_FRUIT_LEFT],
248
- ["vegetables can not talk", MESSAGES.DOMAIN.VEGETABLES_DO_NOT_TALK_ERROR.VEGETABLES_CAN_NOT_TALK],
249
- ["% is not hungry and cannot be fed", MESSAGES.DOMAIN.PERSON_NOT_HUNGRY_ERROR.IS_NOT_HUNGRY_AND_CANNOT_BE_FED],
250
- ["Portion size expected to be a positive integer", MESSAGES.DOMAIN.PORTIONS_ERROR.PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER],
251
- ["Too many portions", MESSAGES.DOMAIN.PORTIONS_ERROR.TOO_MANY_PORTIONS]
252
- ])("provides error message \"%s\" correctly", (a, b) => {
253
- expect(a).toEqual(b)
254
- })
255
- })
1
+ // tests
2
+
3
+ const {
4
+ immediateError,
5
+ ErrorType,
6
+ throwWhatever,
7
+ getError,
8
+ MESSAGES
9
+ } = require("./index")
10
+
11
+ describe("immediateError utility", () => {
12
+ test("throws a regular Error with default message when no arguments are passed", () => {
13
+ expect(() => immediateError()).toThrow(Error)
14
+ expect(() => immediateError()).toThrow("ERROR!")
15
+ })
16
+
17
+ test("throws a regular Error with a custom message", () => {
18
+ expect(() => immediateError("Aaaaah")).toThrow(Error)
19
+ expect(() => immediateError("Aaaaah")).toThrow("Aaaaah")
20
+ })
21
+
22
+ test.each([
23
+ ["BaseError", ErrorType.BaseError, Error],
24
+ ["EvalError", ErrorType.EvalError, EvalError],
25
+ ["RangeError", ErrorType.RangeError, RangeError],
26
+ ["ReferenceError", ErrorType.ReferenceError, ReferenceError],
27
+ ["SyntaxError", ErrorType.SyntaxError, SyntaxError],
28
+ ["TypeError", ErrorType.TypeError, TypeError],
29
+ ["URIError", ErrorType.URIError, URIError],
30
+ ])("throws % when specified", (name, type, constructor) => {
31
+ expect(() => immediateError("test message", type)).toThrow(constructor)
32
+ })
33
+
34
+ test.each([
35
+ ["FruitConsumptionError", ErrorType.FruitConsumptionError],
36
+ ["VegetablesDoNotTalkError", ErrorType.VegetablesDoNotTalkError],
37
+ ["PersonNotHungryError", ErrorType.PersonNotHungryError],
38
+ ["PortionsError", ErrorType.PortionsError],
39
+ ["FalseJSValidationFailedToPassError", ErrorType.FalseJSValidationFailedToPassError]
40
+ ])("throws domain-specific % correctly", (name, type) => {
41
+ const expectedConstructor = getError(type)
42
+ expect(() => immediateError("enterprise failure", type)).toThrow(expectedConstructor)
43
+ expect(() => immediateError("enterprise failure", type)).toThrow("enterprise failure")
44
+ })
45
+
46
+ test("throws a custom user-defined Error class", () => {
47
+ class MyCustomError extends Error {
48
+ constructor(message) {
49
+ super("Custom: " + message)
50
+ this.name = "MyCustomError"
51
+ }
52
+ }
53
+
54
+ expect(() => immediateError("Error!", MyCustomError)).toThrow(MyCustomError)
55
+ expect(() => immediateError("Error!", MyCustomError)).toThrow(
56
+ "Custom: Error!",
57
+ )
58
+ })
59
+
60
+ test("captures stack trace correctly and hides internal frames", () => {
61
+ try {
62
+ immediateError("stack check")
63
+ } catch (error) {
64
+ expect(error.stack).not.toMatch(/at immediateError/)
65
+ }
66
+ })
67
+ })
68
+
69
+ const { attempt } = require("./index")
70
+
71
+ describe("attempt utility", () => {
72
+ test("works as a standard function", () => {
73
+ let called = false
74
+ attempt(() => {
75
+ called = true
76
+ }).end()
77
+ expect(called).toBe(true)
78
+ })
79
+
80
+ test("works as a constructor returning an instance", () => {
81
+ const instance = new attempt(() => {})
82
+ expect(instance).toBeDefined()
83
+ expect(typeof instance.rescue).toBe("function")
84
+ })
85
+
86
+ test("triggers rescue when the handler fails", () => {
87
+ let errorCaught = false
88
+ attempt(() => {
89
+ throw new Error("fail")
90
+ })
91
+ .rescue((e) => {
92
+ errorCaught = true
93
+ expect(e.message).toBe("fail")
94
+ })
95
+ .end()
96
+ expect(errorCaught).toBe(true)
97
+ })
98
+
99
+ test("triggers else only when the handler succeeds", () => {
100
+ let elseCalled = false
101
+ attempt(() => {
102
+ return "success"
103
+ })
104
+ .else(() => {
105
+ elseCalled = true
106
+ })
107
+ .end()
108
+ expect(elseCalled).toBe(true)
109
+ })
110
+
111
+ test("triggers ensure regardless of success or failure", () => {
112
+ let counter = 0
113
+
114
+ attempt(() => {})
115
+ .ensure(() => {
116
+ counter++
117
+ })
118
+ .end()
119
+
120
+ attempt(() => {
121
+ throw new Error()
122
+ })
123
+ .rescue(() => {})
124
+ .ensure(() => {
125
+ counter++
126
+ })
127
+ .end()
128
+
129
+ expect(counter).toBe(2)
130
+ })
131
+
132
+ test("returns this (the instance) from chaining methods", () => {
133
+ const a = attempt(() => {})
134
+ const b = a.rescue(() => {})
135
+ const c = b.else(() => {})
136
+ const d = c.ensure(() => {})
137
+
138
+ expect(a).toBe(d)
139
+ })
140
+ })
141
+
142
+ const { delayedError } = require("./index")
143
+
144
+ describe("delayedError utility", () => {
145
+ const SHORT_DELAY = 10
146
+
147
+ test("throws the error after a specified delay", async () => {
148
+ const start = Date.now()
149
+
150
+ try {
151
+ await delayedError("Delayed fail", ErrorType.BaseError, SHORT_DELAY)
152
+ } catch (error) {
153
+ const duration = Date.now() - start
154
+ expect(duration).toBeGreaterThanOrEqual(SHORT_DELAY)
155
+ expect(error.message).toBe("Delayed fail")
156
+ }
157
+ })
158
+
159
+ test("uses default error message and type if only delay is provided", async () => {
160
+ try {
161
+ await delayedError(undefined, undefined, SHORT_DELAY)
162
+ } catch (error) {
163
+ expect(error.message).toBe("ERROR!")
164
+ expect(error).toBeInstanceOf(Error)
165
+ }
166
+ })
167
+
168
+ test("respects custom error types in delayed mode", async () => {
169
+ try {
170
+ await delayedError("Type fail", ErrorType.TypeError, SHORT_DELAY)
171
+ } catch (error) {
172
+ expect(error).toBeInstanceOf(TypeError)
173
+ expect(error.message).toBe("Type fail")
174
+ }
175
+ })
176
+ })
177
+
178
+ describe("throwWhatever utility", () => {
179
+ test("throws a standard error object when passed", () => {
180
+ const err = new Error("standard fail")
181
+ expect(() => throwWhatever(err)).toThrow("standard fail")
182
+ })
183
+
184
+ test("throws primitive false when passed false", () => {
185
+ try {
186
+ throwWhatever(false)
187
+ } catch (e) {
188
+ expect(e).toBe(false)
189
+ }
190
+ })
191
+
192
+ test("throws primitive zero when passed 0", () => {
193
+ try {
194
+ throwWhatever(0)
195
+ } catch (e) {
196
+ expect(e).toBe(0)
197
+ }
198
+ })
199
+
200
+ test("throws a string directly when passed a string", () => {
201
+ expect(() => throwWhatever("Direct String")).toThrow("Direct String")
202
+ })
203
+
204
+ test("integrates with getError for custom domain errors", () => {
205
+ const FruitError = getError(ErrorType.FruitConsumptionError)
206
+ const err = new FruitError("Too many apples")
207
+ expect(() => throwWhatever(err)).toThrow(FruitError)
208
+ })
209
+ })
210
+
211
+ describe("getError utility", () => {
212
+ test("returns the intrinsic Error constructor for BaseError", () => {
213
+ const result = getError(ErrorType.BaseError)
214
+ expect(result).toBe(Error)
215
+ })
216
+
217
+ test("returns the intrinsic TypeError constructor for TypeError", () => {
218
+ const result = getError(ErrorType.TypeError)
219
+ expect(result).toBe(TypeError)
220
+ })
221
+
222
+ test("successfully extracts FruitConsumptionError from jsfruit logic", () => {
223
+ const FruitError = getError(ErrorType.FruitConsumptionError)
224
+ expect(typeof FruitError).toBe("function")
225
+ const instance = new FruitError("test")
226
+ expect(instance).toBeInstanceOf(Error)
227
+ })
228
+
229
+ test("successfully extracts PersonNotHungryError from libperson logic", () => {
230
+ const HungerError = getError(ErrorType.PersonNotHungryError)
231
+ expect(typeof HungerError).toBe("function")
232
+ expect(new HungerError()).toBeDefined()
233
+ })
234
+
235
+ test("successfully extracts PortionsError from libguacamole logic", () => {
236
+ const GuacError = getError(ErrorType.PortionsError)
237
+ expect(typeof GuacError).toBe("function")
238
+ expect(GuacError.name).toBe("PortionsError")
239
+ })
240
+
241
+ test("successfully extracts FalseJSValidationFailedToPassError", () => {
242
+ const FalseJSValidationFailedToPassError = getError(ErrorType.FalseJSValidationFailedToPassError)
243
+ expect(typeof FalseJSValidationFailedToPassError).toBe("function")
244
+ expect(FalseJSValidationFailedToPassError.name).toBe("FalseJSValidationFailedToPassError")
245
+ })
246
+
247
+ test("returns the same constructor when passed a constructor (identity)", () => {
248
+ class MyError extends Error {}
249
+ const result = getError(MyError)
250
+ expect(result).toBe(MyError)
251
+ })
252
+ })
253
+
254
+ describe("error messages", () => {
255
+ test.each([
256
+ ["no fruit left", MESSAGES.DOMAIN.FRUIT_CONSUMPTION_ERROR.NO_FRUIT_LEFT],
257
+ ["vegetables can not talk", MESSAGES.DOMAIN.VEGETABLES_DO_NOT_TALK_ERROR.VEGETABLES_CAN_NOT_TALK],
258
+ ["% is not hungry and cannot be fed", MESSAGES.DOMAIN.PERSON_NOT_HUNGRY_ERROR.IS_NOT_HUNGRY_AND_CANNOT_BE_FED],
259
+ ["Portion size expected to be a positive integer", MESSAGES.DOMAIN.PORTIONS_ERROR.PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER],
260
+ ["Too many portions", MESSAGES.DOMAIN.PORTIONS_ERROR.TOO_MANY_PORTIONS],
261
+ ["Validation failed to pass", MESSAGES.DOMAIN.FALSEJS_VALIDATION_FAILED_TO_PASS_ERROR.VALIDATION_FAILED_TO_PASS]
262
+ ])("provides error message \"%s\" correctly", (a, b) => {
263
+ expect(a).toEqual(b)
264
+ })
265
+ })
package/jest.config.js CHANGED
@@ -9,4 +9,6 @@ module.exports = {
9
9
  "/x/",
10
10
  "/stfbank/"
11
11
  ]
12
- }
12
+ }
13
+
14
+ // Jest Config
package/package.json CHANGED
@@ -1,138 +1,140 @@
1
- {
2
- "name": "immediate-error",
3
- "version": "12.2.0",
4
- "description": "enterprise errors",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "jest index.test.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/enterprise-npm-ai/immediate-error.git"
12
- },
13
- "keywords": [
14
- "error",
15
- "throw",
16
- "immediate-error",
17
- "tool",
18
- "10x'ness",
19
- "10x'ly made",
20
- "10x",
21
- "10x-engineer",
22
- "10x engineer",
23
- "10x engineering",
24
- "jsfruit",
25
- "libperson",
26
- "libvegetable",
27
- "bail",
28
- "throw-error",
29
- "sigma",
30
- "lifesaver",
31
- "framework",
32
- "js",
33
- "ecmascript",
34
- "javascript",
35
- "licensed",
36
- "jest",
37
- "67",
38
- "fp",
39
- "enterprise-npm-ai",
40
- "sigmaskibidi",
41
- "tj-commits",
42
- "skibidi-toilet-hacker",
43
- "stevelib"
44
- ],
45
- "author": "10x'ly Made",
46
- "license": "Unlicense",
47
- "bugs": {
48
- "url": "https://github.com/enterprise-npm-ai/immediate-error/issues"
49
- },
50
- "homepage": "https://github.com/enterprise-npm-ai/immediate-error#readme",
51
- "dependencies": {
52
- "@10xly/strict-equals": "1.0.1",
53
- "@characters/right-parenthesis": "2.1.0",
54
- "@extra-array/head": "^2.10.19",
55
- "@extra-array/last": "^2.10.19",
56
- "@is-(unknown)/is-false": "1.5.0",
57
- "@is-(unknown)/is-nan": "1.0.0",
58
- "@is-(unknown)/is-negative-zero": "1.0.0",
59
- "@is-(unknown)/is-nil": "1.2.0",
60
- "@is-(unknown)/is-null": "1.3.0",
61
- "@is-(unknown)/is-string": "^1.0.0",
62
- "@is-(unknown)/is-undefined": "1.3.0",
63
- "@negative-numbers/eighty-seven": "^1.0.0",
64
- "@negative-numbers/zero": "1.0.0",
65
- "@positive-numbers/eight": "^3.0.0",
66
- "@positive-numbers/eleven": "^3.0.0",
67
- "@positive-numbers/five": "^3.0.0",
68
- "@positive-numbers/four": "^3.0.0",
69
- "@positive-numbers/nine": "^3.0.0",
70
- "@positive-numbers/one": "^3.0.0",
71
- "@positive-numbers/seven": "^3.0.0",
72
- "@positive-numbers/seventeen": "^3.0.0",
73
- "@positive-numbers/six": "^3.0.0",
74
- "@positive-numbers/ten": "^3.0.0",
75
- "@positive-numbers/thirty-three": "^3.0.0",
76
- "@positive-numbers/three": "^3.0.0",
77
- "@positive-numbers/twenty-five": "^4.0.0",
78
- "@positive-numbers/twenty-nine": "^3.0.0",
79
- "@positive-numbers/two": "^3.0.0",
80
- "@positive-numbers/zero": "^5.0.0",
81
- "@redux-saga/delay-p": "^1.3.1",
82
- "@rightpad/concat": "^1.0.0",
83
- "@rightpad/convert2string": "^1.0.0",
84
- "@uppercase-letters/e": "^3.0.0",
85
- "@uppercase-letters/o": "^3.0.0",
86
- "@uppercase-letters/r": "^3.0.0",
87
- "array-get-member": "^1.0.3",
88
- "array.prototype.join": "^1.0.4",
89
- "attempt-statement": "^1.2.1",
90
- "bail": "^1.0.5",
91
- "basic-functions": "^1.0.6",
92
- "bigint-intrinsic-ai": "1.0.0",
93
- "construct-new": "^2.0.3",
94
- "deep-freeze-node3": "^1.1.0",
95
- "empty-string": "1.1.1",
96
- "es-error-intrinsics": "^1.0.1",
97
- "es-intrinsic-cache": "^1.0.1",
98
- "es-logical-nullish-coalescing-operator": "^1.0.0",
99
- "false-value": "^2.0.6",
100
- "fizzbuzz-enterprise": "^1.0.0",
101
- "for-each": "^0.3.5",
102
- "function-bind": "^1.1.2",
103
- "get-member": "^1337.69.420",
104
- "is-": "^1.0.0",
105
- "is-not-integer": "^1.0.2",
106
- "jsfruit": "^1.1.0",
107
- "libguacamole": "^1.0.0",
108
- "libperson": "^1.0.0",
109
- "libvegetable": "^1.0.0",
110
- "lodash.stubarray": "^4.13.0",
111
- "lolite.__private.multiplyfallback": "^1.1.17",
112
- "node-call.then": "^1.0.0",
113
- "noop-enterprise": "^2.0.1",
114
- "noop10": "1.0.3",
115
- "numero": "^0.1.1",
116
- "object.entries-ponyfill": "^1.0.1",
117
- "object.prototype-intrinsic-ai": "^1.0.1",
118
- "positive-zero": "3.0.0",
119
- "primitive-value-nan": "1.0.1",
120
- "primitive-value-null": "1.0.0",
121
- "primitive-value-undefined": "1.0.0",
122
- "qc-core": "^0.0.0",
123
- "repeating": "^2.0.1",
124
- "simple-lru-cache": "^0.0.2",
125
- "str-replaceallof-es": "1.0.0",
126
- "string.prototype.at": "^1.0.6",
127
- "string.prototype.replaceall": "1.0.11",
128
- "string.prototype.split": "^1.0.9",
129
- "subtract": "^0.0.3",
130
- "true-value": "^3.0.0",
131
- "uncurry-x": "^1.0.1",
132
- "unicode": "^14.0.0",
133
- "utf8-byte-length": "^1.0.5"
134
- },
135
- "devDependencies": {
136
- "jest": "^30.2.0"
137
- }
138
- }
1
+ {
2
+ "name": "immediate-error",
3
+ "version": "12.2.2",
4
+ "description": "enterprise errors",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "jest index.test.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/enterprise-npm-ai/immediate-error.git"
12
+ },
13
+ "keywords": [
14
+ "error",
15
+ "throw",
16
+ "immediate-error",
17
+ "tool",
18
+ "10x'ness",
19
+ "10x'ly made",
20
+ "10x",
21
+ "10x-engineer",
22
+ "10x engineer",
23
+ "10x engineering",
24
+ "jsfruit",
25
+ "libperson",
26
+ "libvegetable",
27
+ "bail",
28
+ "throw-error",
29
+ "sigma",
30
+ "lifesaver",
31
+ "framework",
32
+ "js",
33
+ "ecmascript",
34
+ "javascript",
35
+ "licensed",
36
+ "jest",
37
+ "67",
38
+ "fp",
39
+ "enterprise-npm-ai",
40
+ "sigmaskibidi",
41
+ "tj-commits",
42
+ "skibidi-toilet-hacker",
43
+ "stevelib"
44
+ ],
45
+ "author": "10x'ly Made",
46
+ "license": "EGPSL10X-1.0",
47
+ "bugs": {
48
+ "url": "https://github.com/enterprise-npm-ai/immediate-error/issues"
49
+ },
50
+ "homepage": "https://github.com/enterprise-npm-ai/immediate-error#readme",
51
+ "dependencies": {
52
+ "@10xly/strict-equals": "1.0.1",
53
+ "@characters/right-parenthesis": "2.1.0",
54
+ "@extra-array/head": "^2.10.19",
55
+ "@extra-array/last": "^2.10.19",
56
+ "@falsejs/validation-failed-to-pass-error": "^1.0.1",
57
+ "@is-(unknown)/is-false": "1.5.0",
58
+ "@is-(unknown)/is-nan": "1.0.0",
59
+ "@is-(unknown)/is-negative-zero": "1.0.0",
60
+ "@is-(unknown)/is-nil": "1.2.0",
61
+ "@is-(unknown)/is-null": "1.3.0",
62
+ "@is-(unknown)/is-string": "^1.0.0",
63
+ "@is-(unknown)/is-undefined": "1.3.0",
64
+ "@negative-numbers/eighty-seven": "^1.0.0",
65
+ "@negative-numbers/zero": "1.0.0",
66
+ "@positive-numbers/eight": "^3.0.0",
67
+ "@positive-numbers/eleven": "^3.0.0",
68
+ "@positive-numbers/five": "^3.0.0",
69
+ "@positive-numbers/four": "^3.0.0",
70
+ "@positive-numbers/nine": "^3.0.0",
71
+ "@positive-numbers/one": "^3.0.0",
72
+ "@positive-numbers/seven": "^3.0.0",
73
+ "@positive-numbers/seventeen": "^3.0.0",
74
+ "@positive-numbers/six": "^3.0.0",
75
+ "@positive-numbers/ten": "^3.0.0",
76
+ "@positive-numbers/thirty-three": "^3.0.0",
77
+ "@positive-numbers/three": "^3.0.0",
78
+ "@positive-numbers/twenty-five": "^4.0.0",
79
+ "@positive-numbers/twenty-nine": "^3.0.0",
80
+ "@positive-numbers/two": "^3.0.0",
81
+ "@positive-numbers/zero": "^5.0.0",
82
+ "@redux-saga/delay-p": "^1.3.1",
83
+ "@rightpad/concat": "^1.0.0",
84
+ "@rightpad/convert2string": "^1.0.0",
85
+ "@uppercase-letters/e": "^3.0.0",
86
+ "@uppercase-letters/o": "^3.0.0",
87
+ "@uppercase-letters/r": "^3.0.0",
88
+ "array-get-member": "^1.0.4",
89
+ "array.prototype.join": "^1.0.4",
90
+ "attempt-statement": "^1.2.1",
91
+ "bail": "^1.0.5",
92
+ "basic-functions": "^1.0.6",
93
+ "bigint-intrinsic-ai": "1.0.0",
94
+ "construct-new": "^2.0.8",
95
+ "deep-freeze-node3": "^1.1.0",
96
+ "empty-string": "1.1.1",
97
+ "es-error-intrinsics": "^1.0.1",
98
+ "es-intrinsic-cache": "^1.0.1",
99
+ "es-logical-nullish-coalescing-operator": "^1.0.0",
100
+ "false-value": "^2.0.6",
101
+ "fizzbuzz-enterprise": "^1.0.0",
102
+ "for-each": "^0.3.5",
103
+ "function-bind": "^1.1.2",
104
+ "get-member": "^1337.69.420",
105
+ "is-": "^1.0.0",
106
+ "is-not-integer": "^1.0.2",
107
+ "jsfruit": "^1.1.0",
108
+ "libguacamole": "^1.0.0",
109
+ "libperson": "^1.0.0",
110
+ "libvegetable": "^1.0.0",
111
+ "lodash.stubarray": "^4.13.0",
112
+ "lolite.__private.multiplyfallback": "^1.1.17",
113
+ "node-call.then": "^1.0.0",
114
+ "none": "^1.0.0",
115
+ "noop-enterprise": "^2.0.1",
116
+ "noop10": "1.0.3",
117
+ "numero": "^0.1.1",
118
+ "object.entries-ponyfill": "^1.0.1",
119
+ "object.prototype-intrinsic-ai": "^1.0.1",
120
+ "positive-zero": "3.0.0",
121
+ "primitive-value-nan": "1.0.1",
122
+ "primitive-value-null": "1.0.0",
123
+ "primitive-value-undefined": "1.0.0",
124
+ "qc-core": "^0.0.0",
125
+ "repeating": "^2.0.1",
126
+ "simple-lru-cache": "^0.0.2",
127
+ "str-replaceallof-es": "1.0.0",
128
+ "string.prototype.at": "^1.0.6",
129
+ "string.prototype.replaceall": "1.0.11",
130
+ "string.prototype.split": "^1.0.9",
131
+ "subtract": "^0.0.3",
132
+ "true-value": "^3.0.0",
133
+ "uncurry-x": "^1.0.1",
134
+ "unicode": "^14.0.0",
135
+ "utf8-byte-length": "^1.0.5"
136
+ },
137
+ "devDependencies": {
138
+ "jest": "^30.2.0"
139
+ }
140
+ }