immediate-error 12.2.1 → 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/README.md +3 -0
- package/index.d.ts +5 -0
- package/index.js +8 -0
- package/index.test.js +265 -257
- package/package.json +140 -139
package/README.md
CHANGED
|
@@ -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
|
package/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export enum ErrorType {
|
|
|
11
11
|
VegetablesDoNotTalkError = 8,
|
|
12
12
|
PersonNotHungryError = 9,
|
|
13
13
|
PortionsError = 10,
|
|
14
|
+
FalseJSValidationFailedToPassError = 11
|
|
14
15
|
}
|
|
15
16
|
export type CustomError = {
|
|
16
17
|
new (message: string): Error
|
|
@@ -32,6 +33,7 @@ export function getError(
|
|
|
32
33
|
): CustomError
|
|
33
34
|
export function getError(errorType: ErrorType.PersonNotHungryError): CustomError
|
|
34
35
|
export function getError(errorType: ErrorType.PortionsError): CustomError
|
|
36
|
+
export function getError(errorType: ErrorType.FalseJSValidationFailedToPassError): CustomError
|
|
35
37
|
export function getError(errorType: ErrorType | CustomError): CustomError
|
|
36
38
|
export function immediateError(
|
|
37
39
|
message?: string,
|
|
@@ -78,6 +80,9 @@ export const MESSAGES: {
|
|
|
78
80
|
PORTIONS_ERROR: {
|
|
79
81
|
PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: "Portion size expected to be a positive integer",
|
|
80
82
|
TOO_MANY_PORTIONS: "Too many portions"
|
|
83
|
+
},
|
|
84
|
+
FALSEJS_VALIDATION_FAILED_TO_PASS_ERROR: {
|
|
85
|
+
VALIDATION_FAILED_TO_PASS: "Validation failed to pass"
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
}
|
package/index.js
CHANGED
|
@@ -114,6 +114,8 @@ const $SyntaxError = require("es-error-intrinsics/SyntaxError")
|
|
|
114
114
|
const $TypeError = require("es-error-intrinsics/TypeError")
|
|
115
115
|
const $URIError = require("es-error-intrinsics/URIError")
|
|
116
116
|
|
|
117
|
+
const FalseJSValidationFailedToPassError = require("@falsejs/validation-failed-to-pass-error")
|
|
118
|
+
|
|
117
119
|
const captureStackTrace = GetIntrinsic("%Error.captureStackTrace%", trueValue())
|
|
118
120
|
|
|
119
121
|
const default_error = concat(E, R, R, O, R, EXCLAMATION_POINT)
|
|
@@ -130,6 +132,7 @@ const ErrorType = deepFreeze({
|
|
|
130
132
|
VegetablesDoNotTalkError: eight,
|
|
131
133
|
PersonNotHungryError: nine,
|
|
132
134
|
PortionsError: ten,
|
|
135
|
+
FalseJSValidationFailedToPassError: eleven
|
|
133
136
|
})
|
|
134
137
|
|
|
135
138
|
const ErrorMap = construct({
|
|
@@ -285,6 +288,8 @@ objGetMember(
|
|
|
285
288
|
return result
|
|
286
289
|
}),
|
|
287
290
|
)
|
|
291
|
+
|
|
292
|
+
ErrorMap.set(ErrorType.FalseJSValidationFailedToPassError, FalseJSValidationFailedToPassError)
|
|
288
293
|
})
|
|
289
294
|
|
|
290
295
|
function CreateSleepFunction(delay) {
|
|
@@ -399,6 +404,9 @@ exports.MESSAGES = {
|
|
|
399
404
|
PORTIONS_ERROR: {
|
|
400
405
|
PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: portionSizeExpectedToBeAPositiveIntegerMessage,
|
|
401
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.
|
|
402
410
|
}
|
|
403
411
|
}
|
|
404
412
|
}
|
package/index.test.js
CHANGED
|
@@ -1,257 +1,265 @@
|
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expect(() => immediateError("enterprise failure", type)).toThrow(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
expect(() => immediateError("Error!", MyCustomError)).toThrow(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
expect(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
expect(error).
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
expect(error
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
expect(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
expect(GuacError
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
expect(
|
|
244
|
-
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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/package.json
CHANGED
|
@@ -1,139 +1,140 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "immediate-error",
|
|
3
|
-
"version": "12.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
|
-
"@
|
|
57
|
-
"@is-(unknown)/is-
|
|
58
|
-
"@is-(unknown)/is-
|
|
59
|
-
"@is-(unknown)/is-
|
|
60
|
-
"@is-(unknown)/is-
|
|
61
|
-
"@is-(unknown)/is-
|
|
62
|
-
"@is-(unknown)/is-
|
|
63
|
-
"@
|
|
64
|
-
"@negative-numbers/
|
|
65
|
-
"@
|
|
66
|
-
"@positive-numbers/
|
|
67
|
-
"@positive-numbers/
|
|
68
|
-
"@positive-numbers/
|
|
69
|
-
"@positive-numbers/
|
|
70
|
-
"@positive-numbers/
|
|
71
|
-
"@positive-numbers/
|
|
72
|
-
"@positive-numbers/
|
|
73
|
-
"@positive-numbers/
|
|
74
|
-
"@positive-numbers/
|
|
75
|
-
"@positive-numbers/
|
|
76
|
-
"@positive-numbers/three": "^3.0.0",
|
|
77
|
-
"@positive-numbers/
|
|
78
|
-
"@positive-numbers/twenty-
|
|
79
|
-
"@positive-numbers/
|
|
80
|
-
"@positive-numbers/
|
|
81
|
-
"@
|
|
82
|
-
"@
|
|
83
|
-
"@rightpad/
|
|
84
|
-
"@
|
|
85
|
-
"@uppercase-letters/
|
|
86
|
-
"@uppercase-letters/
|
|
87
|
-
"
|
|
88
|
-
"array
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"es-
|
|
98
|
-
"es-
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"is-
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"object.
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"primitive-value-
|
|
122
|
-
"primitive-value-
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"string.prototype.
|
|
129
|
-
"string.prototype.
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
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
|
+
}
|