immediate-error 12.0.0 → 12.2.0
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 +16 -3
- package/index.d.ts +44 -37
- package/index.js +74 -19
- package/index.test.js +39 -13
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -34,10 +34,12 @@ immediateError("URI Error", ErrorType.URIError) // throws a URIError
|
|
|
34
34
|
|
|
35
35
|
immediateError("fruit consumption error", ErrorType.FruitConsumptionError) // throws FruitConsumptionError
|
|
36
36
|
|
|
37
|
-
immediateError("vegetables
|
|
37
|
+
immediateError("vegetables do not talk error", ErrorType.VegetablesDoNotTalkError) // throws a VegetablesDoNotTalkError
|
|
38
38
|
|
|
39
39
|
immediateError("person not hungry error", ErrorType.PersonNotHungryError) // throws a PersonNotHungryError
|
|
40
40
|
|
|
41
|
+
immediateError("portions error", ErrorType.PortionsError) // throws a PortionsError
|
|
42
|
+
|
|
41
43
|
class MyCustomError extends Error {
|
|
42
44
|
constructor (message) {
|
|
43
45
|
super("Custom: " + message)
|
|
@@ -59,7 +61,7 @@ const TypeErrorConstructor = getError(ErrorType.TypeError)
|
|
|
59
61
|
|
|
60
62
|
console.log(TypeErrorConstructor === TypeError) // true
|
|
61
63
|
|
|
62
|
-
const
|
|
64
|
+
const VegetablesDoNotTalkError = getError(ErrorType.VegetablesDoNotTalkError)
|
|
63
65
|
|
|
64
66
|
try {
|
|
65
67
|
const Vegetable = require("libvegetable")
|
|
@@ -67,7 +69,7 @@ try {
|
|
|
67
69
|
|
|
68
70
|
vegetable.greet()
|
|
69
71
|
} catch (error) {
|
|
70
|
-
console.log(error.constructor ===
|
|
72
|
+
console.log(error.constructor === VegetablesDoNotTalkError) // true
|
|
71
73
|
}
|
|
72
74
|
```
|
|
73
75
|
|
|
@@ -96,6 +98,17 @@ const { delayedError, ErrorType } = require("immediate-error")
|
|
|
96
98
|
delayedError("delayed", ErrorType.BaseError, 1000) // waits 1000 ms (1 second) and then throws error
|
|
97
99
|
```
|
|
98
100
|
|
|
101
|
+
Getting Error Messages:
|
|
102
|
+
```js
|
|
103
|
+
// MESSAGES includes all error messages generally thrown from domain-specic enterprise errors
|
|
104
|
+
const { MESSAGES } = require("immediate-error")
|
|
105
|
+
console.log(MESSAGES.DOMAIN.FRUIT_CONSUMPTION_ERROR.NO_FRUIT_LEFT) // "no fruit left"
|
|
106
|
+
console.log(MESSAGES.DOMAIN.VEGETABLES_DO_NOT_TALK_ERROR.VEGETABLES_CAN_NOT_TALK) // "vegetables can not talk"
|
|
107
|
+
console.log(MESSAGES.DOMAIN.PERSON_NOT_HUNGRY_ERROR.IS_NOT_HUNGRY_AND_CANNOT_BE_FED) // "% is not hungry and cannot be fed"
|
|
108
|
+
console.log(MESSAGES.DOMAIN.PORTIONS_ERROR.PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER) // "Portion size expected to be a positive integer"
|
|
109
|
+
console.log(MESSAGES.DOMAIN.PORTIONS_ERROR.TOO_MANY_PORTIONS) // "Too many portions"
|
|
110
|
+
```
|
|
111
|
+
|
|
99
112
|
## `immediate-error` 2.0.0
|
|
100
113
|
|
|
101
114
|
If you are looking for a more lightweight alternative to `immediate-error`'s latest version that has only 2 dependencies, you can use `immediate-error` version 2.0.0:
|
package/index.d.ts
CHANGED
|
@@ -7,69 +7,76 @@ export enum ErrorType {
|
|
|
7
7
|
TypeError = 5,
|
|
8
8
|
URIError = 6,
|
|
9
9
|
FruitConsumptionError = 7,
|
|
10
|
-
|
|
10
|
+
VegetablesDoNotTalkError = 8,
|
|
11
11
|
PersonNotHungryError = 9,
|
|
12
|
+
PortionsError = 10,
|
|
12
13
|
}
|
|
13
|
-
|
|
14
14
|
export type CustomError = {
|
|
15
15
|
new (message: string): Error
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
export function getError(errorType: ErrorType.BaseError): typeof Error
|
|
19
18
|
export function getError(errorType: ErrorType.EvalError): typeof EvalError
|
|
20
19
|
export function getError(errorType: ErrorType.RangeError): typeof RangeError
|
|
21
20
|
export function getError(
|
|
22
|
-
errorType: ErrorType.ReferenceError
|
|
21
|
+
errorType: ErrorType.ReferenceError,
|
|
23
22
|
): typeof ReferenceError
|
|
24
23
|
export function getError(errorType: ErrorType.SyntaxError): typeof SyntaxError
|
|
25
24
|
export function getError(errorType: ErrorType.TypeError): typeof TypeError
|
|
26
25
|
export function getError(errorType: ErrorType.URIError): typeof URIError
|
|
27
26
|
export function getError(
|
|
28
|
-
errorType: ErrorType.FruitConsumptionError
|
|
27
|
+
errorType: ErrorType.FruitConsumptionError,
|
|
29
28
|
): CustomError
|
|
30
29
|
export function getError(
|
|
31
|
-
errorType: ErrorType.
|
|
30
|
+
errorType: ErrorType.VegetablesDoNotTalkError,
|
|
32
31
|
): CustomError
|
|
33
32
|
export function getError(errorType: ErrorType.PersonNotHungryError): CustomError
|
|
33
|
+
export function getError(errorType: ErrorType.PortionsError): CustomError
|
|
34
34
|
export function getError(errorType: ErrorType | CustomError): CustomError
|
|
35
|
-
|
|
36
35
|
export function immediateError(
|
|
37
36
|
message?: string,
|
|
38
|
-
errorType?: ErrorType | CustomError
|
|
37
|
+
errorType?: ErrorType | CustomError,
|
|
39
38
|
): never
|
|
40
|
-
|
|
41
39
|
export function throwWhatever(whateverToThrow: any): never
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
export const attempt: {
|
|
41
|
+
new (handler?: () => void): {
|
|
42
|
+
trycode?: () => void
|
|
43
|
+
rescuehandler?: (error: any) => void
|
|
44
|
+
elsehandler?: () => void
|
|
45
|
+
ensurehandler?: (error: any) => void
|
|
46
|
+
rescue(handler: (error: any) => void): this
|
|
47
|
+
else(handler: () => void): this
|
|
48
|
+
ensure(handler: () => void): this
|
|
49
|
+
end(): void
|
|
50
|
+
}
|
|
51
|
+
(handler?: () => void): {
|
|
52
|
+
trycode?: () => void
|
|
53
|
+
rescuehandler?: (error: any) => void
|
|
54
|
+
elsehandler?: () => void
|
|
55
|
+
ensurehandler?: (error: any) => void
|
|
56
|
+
rescue(handler: (error: any) => void): this
|
|
57
|
+
else(handler: () => void): this
|
|
58
|
+
ensure(handler: () => void): this
|
|
59
|
+
end(): void
|
|
60
|
+
}
|
|
47
61
|
}
|
|
48
|
-
|
|
49
|
-
declare class Attempt {
|
|
50
|
-
constructor(handler?: () => void)
|
|
51
|
-
|
|
52
|
-
trycode?: () => void
|
|
53
|
-
rescuehandler?: (error: any) => void
|
|
54
|
-
elsehandler?: () => void
|
|
55
|
-
ensurehandler?: (error: any) => void
|
|
56
|
-
|
|
57
|
-
rescue(handler: (error: any) => void): this
|
|
58
|
-
else(handler: () => void): this
|
|
59
|
-
ensure(handler: () => void): this
|
|
60
|
-
end(): void
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const attempt: AttemptConstructor
|
|
64
|
-
|
|
65
62
|
export function delayedError(
|
|
66
63
|
message?: string,
|
|
67
64
|
errorType?: ErrorType | CustomError,
|
|
68
|
-
delay?: number
|
|
65
|
+
delay?: number,
|
|
69
66
|
): Promise<never>
|
|
70
67
|
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
export const MESSAGES: {
|
|
69
|
+
DOMAIN: {
|
|
70
|
+
FRUIT_CONSUMPTION_ERROR: { NO_FRUIT_LEFT: "no fruit left" }
|
|
71
|
+
VEGETABLES_DO_NOT_TALK_ERROR: {
|
|
72
|
+
VEGETABLES_CAN_NOT_TALK: "vegetables can not talk"
|
|
73
|
+
}
|
|
74
|
+
PERSON_NOT_HUNGRY_ERROR: {
|
|
75
|
+
IS_NOT_HUNGRY_AND_CANNOT_BE_FED: "% is not hungry and cannot be fed"
|
|
76
|
+
},
|
|
77
|
+
PORTIONS_ERROR: {
|
|
78
|
+
PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: "Portion size expected to be a positive integer",
|
|
79
|
+
TOO_MANY_PORTIONS: "Too many portions"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/index.js
CHANGED
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
const GetIntrinsic = require("es-intrinsic-cache")
|
|
7
7
|
const SimpleCache = require("simple-lru-cache")
|
|
8
|
-
eval(require("javascript-interpreter"))
|
|
9
|
-
let interpret = require("javascript-interpreter/interpret")
|
|
10
8
|
const Fruit = require("jsfruit")
|
|
11
9
|
const Vegetable = require("libvegetable")
|
|
12
10
|
const Person = require("libperson")
|
|
11
|
+
const Guacamole = require("libguacamole")
|
|
13
12
|
const isEqual = require("@10xly/strict-equals")
|
|
14
13
|
const isdash = require("is-")
|
|
15
14
|
const noop = require("noop-enterprise")
|
|
@@ -19,7 +18,7 @@ const construct = require("construct-new")
|
|
|
19
18
|
const toStr = require("@rightpad/convert2string")
|
|
20
19
|
const attempt = require("attempt-statement")
|
|
21
20
|
const trueValue = require("true-value")
|
|
22
|
-
const asArray =
|
|
21
|
+
const asArray = x => [x] // behind bars
|
|
23
22
|
const isString = require("@is-(unknown)/is-string")
|
|
24
23
|
const repeating = require("repeating")
|
|
25
24
|
const deepFreeze = require("deep-freeze-node3") // 3rd iteration of deep-freeze-node, and the only 10x one.
|
|
@@ -71,6 +70,8 @@ const isNull = require("@is-(unknown)/is-null")
|
|
|
71
70
|
const isUndefined = require("@is-(unknown)/is-undefined")
|
|
72
71
|
const isNaN = require("@is-(unknown)/is-nan")
|
|
73
72
|
|
|
73
|
+
const multiply = require("lolite.__private.multiplyfallback")
|
|
74
|
+
|
|
74
75
|
const nullvalue = require("primitive-value-null")
|
|
75
76
|
const nanvalue = require("primitive-value-nan")
|
|
76
77
|
const undef = require("primitive-value-undefined")
|
|
@@ -89,12 +90,14 @@ const six = require("@positive-numbers/six")
|
|
|
89
90
|
const seven = require("@positive-numbers/seven")
|
|
90
91
|
const eight = require("@positive-numbers/eight")
|
|
91
92
|
const nine = require("@positive-numbers/nine")
|
|
93
|
+
const ten = require("@positive-numbers/ten")
|
|
92
94
|
const eleven = require("@positive-numbers/eleven")
|
|
93
95
|
const seventeen = require("@positive-numbers/seventeen")
|
|
94
96
|
const twentyFive = require("@positive-numbers/twenty-five")
|
|
95
97
|
const twentyNine = require("@positive-numbers/twenty-nine")
|
|
96
98
|
const thirtyThree = require("@positive-numbers/thirty-three")
|
|
97
99
|
const oneHundred = require("fizzbuzz-enterprise/source/main/constants/magic-numbers/Hundred")
|
|
100
|
+
const negative87 = require("@negative-numbers/eighty-seven")
|
|
98
101
|
|
|
99
102
|
const E = require("@uppercase-letters/e")
|
|
100
103
|
const O = require("@uppercase-letters/o")
|
|
@@ -122,8 +125,9 @@ const ErrorType = deepFreeze({
|
|
|
122
125
|
URIError: six,
|
|
123
126
|
|
|
124
127
|
FruitConsumptionError: seven,
|
|
125
|
-
|
|
128
|
+
VegetablesDoNotTalkError: eight,
|
|
126
129
|
PersonNotHungryError: nine,
|
|
130
|
+
PortionsError: ten,
|
|
127
131
|
})
|
|
128
132
|
|
|
129
133
|
const ErrorMap = construct({
|
|
@@ -162,13 +166,16 @@ function createObjectWithTargetKey(value) {
|
|
|
162
166
|
)
|
|
163
167
|
const array = split(string, toStr(target_).substr(twentyNine, six))
|
|
164
168
|
array.shift()
|
|
165
|
-
eval(
|
|
166
|
-
|
|
167
|
-
return interpret(
|
|
168
|
-
interpret(join(array, toStr(target_).substr(twentyNine, six))),
|
|
169
|
+
return eval(
|
|
170
|
+
eval(join(array, toStr(target_).substr(twentyNine, six))),
|
|
169
171
|
)
|
|
170
172
|
}
|
|
171
173
|
|
|
174
|
+
var noFruitLeftMessage
|
|
175
|
+
var vegetablesCanNotTalkMessage
|
|
176
|
+
var personIsNotHungryAndCannotBeFedMessage
|
|
177
|
+
var portionSizeExpectedToBeAPositiveIntegerMessage
|
|
178
|
+
|
|
172
179
|
objGetMember(
|
|
173
180
|
just,
|
|
174
181
|
"call",
|
|
@@ -190,14 +197,11 @@ objGetMember(
|
|
|
190
197
|
const fruit = construct(createObjectWithTargetKey(Fruit))
|
|
191
198
|
let result
|
|
192
199
|
attempt(() => {
|
|
193
|
-
fruit
|
|
194
|
-
eval(require("javascript-interpreter"))
|
|
195
|
-
interpret = require("javascript-interpreter/interpret")
|
|
196
|
-
|
|
197
|
-
interpret(repeating(concat("fruit.eat()", NEWLINE), eleven))
|
|
200
|
+
eval(repeating(concat("fruit.eat()", NEWLINE), eleven))
|
|
198
201
|
})
|
|
199
202
|
.rescue((error) => {
|
|
200
203
|
result = error.constructor
|
|
204
|
+
noFruitLeftMessage = error.message
|
|
201
205
|
})
|
|
202
206
|
.else(noop)
|
|
203
207
|
.ensure(noop)
|
|
@@ -208,7 +212,7 @@ objGetMember(
|
|
|
208
212
|
)
|
|
209
213
|
|
|
210
214
|
ErrorMap.set(
|
|
211
|
-
ErrorType.
|
|
215
|
+
ErrorType.VegetablesDoNotTalkError,
|
|
212
216
|
objGetMember(
|
|
213
217
|
just,
|
|
214
218
|
"call",
|
|
@@ -221,6 +225,7 @@ objGetMember(
|
|
|
221
225
|
})
|
|
222
226
|
.rescue((error) => {
|
|
223
227
|
result = error.constructor
|
|
228
|
+
vegetablesCanNotTalkMessage = error.message
|
|
224
229
|
})
|
|
225
230
|
.else(noop)
|
|
226
231
|
.ensure(noop)
|
|
@@ -245,6 +250,7 @@ objGetMember(
|
|
|
245
250
|
})
|
|
246
251
|
.rescue((error) => {
|
|
247
252
|
result = error.constructor
|
|
253
|
+
personIsNotHungryAndCannotBeFedMessage = replaceAll(error.message, "undefined", "%")
|
|
248
254
|
})
|
|
249
255
|
.else(noop)
|
|
250
256
|
.ensure(noop)
|
|
@@ -253,6 +259,30 @@ objGetMember(
|
|
|
253
259
|
return result
|
|
254
260
|
}),
|
|
255
261
|
)
|
|
262
|
+
|
|
263
|
+
ErrorMap.set(
|
|
264
|
+
ErrorType.PortionsError,
|
|
265
|
+
objGetMember(
|
|
266
|
+
just,
|
|
267
|
+
"call",
|
|
268
|
+
)(function () {
|
|
269
|
+
let result
|
|
270
|
+
attempt(() => {
|
|
271
|
+
construct({
|
|
272
|
+
target: Guacamole,
|
|
273
|
+
args: [negative87],
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
.rescue((error) => {
|
|
277
|
+
result = error.constructor
|
|
278
|
+
portionSizeExpectedToBeAPositiveIntegerMessage = error.message
|
|
279
|
+
})
|
|
280
|
+
.else(noop)
|
|
281
|
+
.ensure(noop)
|
|
282
|
+
.end()
|
|
283
|
+
return result
|
|
284
|
+
}),
|
|
285
|
+
)
|
|
256
286
|
})
|
|
257
287
|
|
|
258
288
|
function CreateSleepFunction(delay) {
|
|
@@ -297,11 +327,7 @@ exports.immediateError = function immediateError(message, errorType) {
|
|
|
297
327
|
require("is-not-integer")() // how did we get here?
|
|
298
328
|
}
|
|
299
329
|
|
|
300
|
-
exports.delayedError = function delayedError(
|
|
301
|
-
message,
|
|
302
|
-
errorType,
|
|
303
|
-
delay,
|
|
304
|
-
) {
|
|
330
|
+
exports.delayedError = function delayedError(message, errorType, delay) {
|
|
305
331
|
message = coalesce(message, default_error)
|
|
306
332
|
errorType = coalesce(errorType, ErrorType.BaseError)
|
|
307
333
|
return objGetMember(call, "then")(
|
|
@@ -346,6 +372,35 @@ exports.throwWhatever = function throwWhatever(whateverToThrow) {
|
|
|
346
372
|
}
|
|
347
373
|
}
|
|
348
374
|
|
|
375
|
+
var tooManyPortionsMessage
|
|
376
|
+
|
|
377
|
+
attempt(() => {
|
|
378
|
+
const guacamole = construct({
|
|
379
|
+
target: Guacamole,
|
|
380
|
+
args: [multiply(oneHundred, oneHundred)]
|
|
381
|
+
})
|
|
382
|
+
}).rescue(error => {
|
|
383
|
+
tooManyPortionsMessage = error.message
|
|
384
|
+
}).else(noop).ensure(noop).end()
|
|
385
|
+
|
|
386
|
+
exports.MESSAGES = {
|
|
387
|
+
DOMAIN: {
|
|
388
|
+
FRUIT_CONSUMPTION_ERROR: {
|
|
389
|
+
NO_FRUIT_LEFT: noFruitLeftMessage
|
|
390
|
+
},
|
|
391
|
+
VEGETABLES_DO_NOT_TALK_ERROR: {
|
|
392
|
+
VEGETABLES_CAN_NOT_TALK: vegetablesCanNotTalkMessage
|
|
393
|
+
},
|
|
394
|
+
PERSON_NOT_HUNGRY_ERROR: {
|
|
395
|
+
IS_NOT_HUNGRY_AND_CANNOT_BE_FED: personIsNotHungryAndCannotBeFedMessage
|
|
396
|
+
},
|
|
397
|
+
PORTIONS_ERROR: {
|
|
398
|
+
PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: portionSizeExpectedToBeAPositiveIntegerMessage,
|
|
399
|
+
TOO_MANY_PORTIONS: tooManyPortionsMessage
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
349
404
|
exports.attempt = attempt
|
|
350
405
|
|
|
351
406
|
exports.ErrorType = ErrorType
|
package/index.test.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
immediateError,
|
|
3
|
+
ErrorType,
|
|
4
|
+
throwWhatever,
|
|
5
|
+
getError,
|
|
6
|
+
MESSAGES
|
|
7
|
+
} = require("./index")
|
|
2
8
|
|
|
3
9
|
describe("immediateError utility", () => {
|
|
4
|
-
|
|
5
10
|
test("throws a regular Error with default message when no arguments are passed", () => {
|
|
6
11
|
expect(() => immediateError()).toThrow(Error)
|
|
7
12
|
expect(() => immediateError()).toThrow("ERROR!")
|
|
@@ -20,16 +25,17 @@ describe("immediateError utility", () => {
|
|
|
20
25
|
["SyntaxError", ErrorType.SyntaxError, SyntaxError],
|
|
21
26
|
["TypeError", ErrorType.TypeError, TypeError],
|
|
22
27
|
["URIError", ErrorType.URIError, URIError],
|
|
23
|
-
])("throws %
|
|
28
|
+
])("throws % when specified", (name, type, constructor) => {
|
|
24
29
|
expect(() => immediateError("test message", type)).toThrow(constructor)
|
|
25
30
|
})
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
test.each([
|
|
28
33
|
["FruitConsumptionError", ErrorType.FruitConsumptionError],
|
|
29
|
-
["
|
|
34
|
+
["VegetablesDoNotTalkError", ErrorType.VegetablesDoNotTalkError],
|
|
30
35
|
["PersonNotHungryError", ErrorType.PersonNotHungryError],
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
["PortionsError", ErrorType.PortionsError],
|
|
37
|
+
])("throws domain-specific % correctly", (name, type) => {
|
|
38
|
+
const expectedConstructor = getError(type)
|
|
33
39
|
expect(() => immediateError("enterprise failure", type)).toThrow(expectedConstructor)
|
|
34
40
|
expect(() => immediateError("enterprise failure", type)).toThrow("enterprise failure")
|
|
35
41
|
})
|
|
@@ -43,7 +49,9 @@ describe("immediateError utility", () => {
|
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
expect(() => immediateError("Error!", MyCustomError)).toThrow(MyCustomError)
|
|
46
|
-
expect(() => immediateError("Error!", MyCustomError)).toThrow(
|
|
52
|
+
expect(() => immediateError("Error!", MyCustomError)).toThrow(
|
|
53
|
+
"Custom: Error!",
|
|
54
|
+
)
|
|
47
55
|
})
|
|
48
56
|
|
|
49
57
|
test("captures stack trace correctly and hides internal frames", () => {
|
|
@@ -99,13 +107,13 @@ describe("attempt utility", () => {
|
|
|
99
107
|
|
|
100
108
|
test("triggers ensure regardless of success or failure", () => {
|
|
101
109
|
let counter = 0
|
|
102
|
-
|
|
110
|
+
|
|
103
111
|
attempt(() => {})
|
|
104
112
|
.ensure(() => {
|
|
105
113
|
counter++
|
|
106
114
|
})
|
|
107
115
|
.end()
|
|
108
|
-
|
|
116
|
+
|
|
109
117
|
attempt(() => {
|
|
110
118
|
throw new Error()
|
|
111
119
|
})
|
|
@@ -123,7 +131,7 @@ describe("attempt utility", () => {
|
|
|
123
131
|
const b = a.rescue(() => {})
|
|
124
132
|
const c = b.else(() => {})
|
|
125
133
|
const d = c.ensure(() => {})
|
|
126
|
-
|
|
134
|
+
|
|
127
135
|
expect(a).toBe(d)
|
|
128
136
|
})
|
|
129
137
|
})
|
|
@@ -135,7 +143,7 @@ describe("delayedError utility", () => {
|
|
|
135
143
|
|
|
136
144
|
test("throws the error after a specified delay", async () => {
|
|
137
145
|
const start = Date.now()
|
|
138
|
-
|
|
146
|
+
|
|
139
147
|
try {
|
|
140
148
|
await delayedError("Delayed fail", ErrorType.BaseError, SHORT_DELAY)
|
|
141
149
|
} catch (error) {
|
|
@@ -221,9 +229,27 @@ describe("getError utility", () => {
|
|
|
221
229
|
expect(new HungerError()).toBeDefined()
|
|
222
230
|
})
|
|
223
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
|
+
|
|
224
238
|
test("returns the same constructor when passed a constructor (identity)", () => {
|
|
225
239
|
class MyError extends Error {}
|
|
226
240
|
const result = getError(MyError)
|
|
227
241
|
expect(result).toBe(MyError)
|
|
228
242
|
})
|
|
229
|
-
})
|
|
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
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "immediate-error",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "enterprise errors",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@is-(unknown)/is-null": "1.3.0",
|
|
61
61
|
"@is-(unknown)/is-string": "^1.0.0",
|
|
62
62
|
"@is-(unknown)/is-undefined": "1.3.0",
|
|
63
|
+
"@negative-numbers/eighty-seven": "^1.0.0",
|
|
63
64
|
"@negative-numbers/zero": "1.0.0",
|
|
64
65
|
"@positive-numbers/eight": "^3.0.0",
|
|
65
66
|
"@positive-numbers/eleven": "^3.0.0",
|
|
@@ -70,6 +71,7 @@
|
|
|
70
71
|
"@positive-numbers/seven": "^3.0.0",
|
|
71
72
|
"@positive-numbers/seventeen": "^3.0.0",
|
|
72
73
|
"@positive-numbers/six": "^3.0.0",
|
|
74
|
+
"@positive-numbers/ten": "^3.0.0",
|
|
73
75
|
"@positive-numbers/thirty-three": "^3.0.0",
|
|
74
76
|
"@positive-numbers/three": "^3.0.0",
|
|
75
77
|
"@positive-numbers/twenty-five": "^4.0.0",
|
|
@@ -84,7 +86,6 @@
|
|
|
84
86
|
"@uppercase-letters/r": "^3.0.0",
|
|
85
87
|
"array-get-member": "^1.0.3",
|
|
86
88
|
"array.prototype.join": "^1.0.4",
|
|
87
|
-
"as-array": "^2.0.0",
|
|
88
89
|
"attempt-statement": "^1.2.1",
|
|
89
90
|
"bail": "^1.0.5",
|
|
90
91
|
"basic-functions": "^1.0.6",
|
|
@@ -102,11 +103,12 @@
|
|
|
102
103
|
"get-member": "^1337.69.420",
|
|
103
104
|
"is-": "^1.0.0",
|
|
104
105
|
"is-not-integer": "^1.0.2",
|
|
105
|
-
"javascript-interpreter": "^1.0.0",
|
|
106
106
|
"jsfruit": "^1.1.0",
|
|
107
|
+
"libguacamole": "^1.0.0",
|
|
107
108
|
"libperson": "^1.0.0",
|
|
108
109
|
"libvegetable": "^1.0.0",
|
|
109
110
|
"lodash.stubarray": "^4.13.0",
|
|
111
|
+
"lolite.__private.multiplyfallback": "^1.1.17",
|
|
110
112
|
"node-call.then": "^1.0.0",
|
|
111
113
|
"noop-enterprise": "^2.0.1",
|
|
112
114
|
"noop10": "1.0.3",
|