immediate-error 12.2.1 → 12.2.3
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/.github/workflows/lint.yml +20 -0
- package/README.md +3 -0
- package/eslint.config.mjs +3 -0
- package/index.d.ts +5 -0
- package/index.js +197 -106
- package/index.test.js +266 -257
- package/package.json +144 -139
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: 10xly Code Quality
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["**"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["**"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
quality-check:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: "25"
|
|
17
|
+
- name: Install
|
|
18
|
+
run: npm install
|
|
19
|
+
- name: Run 10xly Lint
|
|
20
|
+
run: npx eslint . --max-warnings 0
|
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
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
// COPYRIGHTE 10X'LY MADE ALL RIGHTS RESIERVED!!!!
|
|
3
|
-
|
|
4
|
-
// DO NOT FORMAT THIS FILE BECAUSE IT MIGHT BREAK
|
|
5
|
-
|
|
6
|
-
require("none")() // performance thing
|
|
1
|
+
require("none")()
|
|
7
2
|
|
|
3
|
+
/* eslint-disable perfectionist/sort-objects, max-lines */
|
|
8
4
|
const GetIntrinsic = require("es-intrinsic-cache")
|
|
9
5
|
const SimpleCache = require("simple-lru-cache")
|
|
10
6
|
const Fruit = require("jsfruit")
|
|
@@ -19,50 +15,60 @@ const bail = require("bail")
|
|
|
19
15
|
const construct = require("construct-new")
|
|
20
16
|
const toStr = require("@rightpad/convert2string")
|
|
21
17
|
const attempt = require("attempt-statement")
|
|
22
|
-
|
|
23
|
-
const asArray =
|
|
18
|
+
// eslint-disable-next-line no-inline-comments
|
|
19
|
+
const asArray = (value) => [value], // Put it behind bars
|
|
20
|
+
trueValue = require("true-value")
|
|
24
21
|
const isString = require("@is-(unknown)/is-string")
|
|
25
22
|
const repeating = require("repeating")
|
|
23
|
+
// eslint-disable-next-line no-inline-comments
|
|
26
24
|
const deepFreeze = require("deep-freeze-node3") // 3rd iteration of deep-freeze-node, and the only 10x one.
|
|
27
25
|
const concat = require("@rightpad/concat")
|
|
28
|
-
const NEWLINE = require("fizzbuzz-enterprise/source/main/constants/strings/delimiters/Newline")
|
|
26
|
+
const NEWLINE = require("fizzbuzz-enterprise/source/main/constants/strings/delimiters/Newline")
|
|
29
27
|
const emptyString = require("empty-string")
|
|
30
|
-
const falseValue = require("false-value")
|
|
31
|
-
|
|
28
|
+
const falseValue = require("false-value"),
|
|
29
|
+
sleep = require("@redux-saga/delay-p").default
|
|
32
30
|
const uncurry = require("uncurry-x")
|
|
33
31
|
const join = require("array.prototype.join")
|
|
34
32
|
const at = require("string.prototype.at")
|
|
35
33
|
const replaceAll = require("str-replaceallof-es")
|
|
36
34
|
const split = require("string.prototype.split")
|
|
37
35
|
const length = require("utf8-byte-length")
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const just = require("basic-functions")
|
|
41
|
-
|
|
36
|
+
const bind = uncurry(require("function-bind")),
|
|
37
|
+
call = require("node-call.then")
|
|
38
|
+
const just = require("basic-functions"),
|
|
39
|
+
// eslint-disable-next-line sort-vars
|
|
40
|
+
Null = require("qc-core").nullFn
|
|
42
41
|
const entries = require("object.entries-ponyfill")
|
|
43
|
-
const
|
|
44
|
-
|
|
42
|
+
const arrayGetMember = uncurry(require("array-get-member").arrayGetMember),
|
|
43
|
+
stubArray = require("lodash.stubarray")
|
|
45
44
|
require("get-member")()
|
|
46
|
-
|
|
47
|
-
const
|
|
45
|
+
// eslint-disable-next-line one-var
|
|
46
|
+
const objectGetMember = uncurry(
|
|
47
|
+
require("object.prototype-intrinsic-ai").getMember,
|
|
48
|
+
),
|
|
49
|
+
// eslint-disable-next-line sort-vars
|
|
50
|
+
ParseFloat = require("numero").parseFloat
|
|
48
51
|
const unicodePo = require("unicode/category/Po")
|
|
49
52
|
const subtract = require("subtract")
|
|
50
53
|
const forEach = require("for-each")
|
|
51
54
|
const head = require("@extra-array/head")
|
|
52
|
-
const last = require("@extra-array/last")
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
)(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const last = require("@extra-array/last"),
|
|
56
|
+
unicodePoArray = objectGetMember(
|
|
57
|
+
just,
|
|
58
|
+
"call",
|
|
59
|
+
)(() => {
|
|
60
|
+
// THIS IS NOT SHADOWING!!!
|
|
61
|
+
// eslint-disable-next-line no-shadow
|
|
62
|
+
const unicodePoArray = stubArray()
|
|
63
|
+
forEach(entries(unicodePo), (entry) => {
|
|
64
|
+
const key = head(entry),
|
|
65
|
+
// eslint-disable-next-line new-cap
|
|
66
|
+
numberKey = ParseFloat(key),
|
|
67
|
+
value = last(entry)
|
|
68
|
+
unicodePoArray[numberKey] = value
|
|
69
|
+
})
|
|
70
|
+
return unicodePoArray
|
|
63
71
|
})
|
|
64
|
-
return unicodePoArray
|
|
65
|
-
})
|
|
66
72
|
const coalesce = require("es-logical-nullish-coalescing-operator")
|
|
67
73
|
const isFalse = require("@is-(unknown)/is-false")
|
|
68
74
|
const isPositiveZero = require("positive-zero")
|
|
@@ -70,7 +76,11 @@ const isNegativeZero = require("@is-(unknown)/is-negative-zero")
|
|
|
70
76
|
const isNullOrUndefined = require("@is-(unknown)/is-nil")
|
|
71
77
|
const isNull = require("@is-(unknown)/is-null")
|
|
72
78
|
const isUndefined = require("@is-(unknown)/is-undefined")
|
|
79
|
+
// eslint-disable-next-line sonarjs/no-globals-shadowing
|
|
73
80
|
const isNaN = require("@is-(unknown)/is-nan")
|
|
81
|
+
const use = require("use-unused-vars")
|
|
82
|
+
|
|
83
|
+
const { TernaryCompare } = require("important-extremely-useful-classes")
|
|
74
84
|
|
|
75
85
|
const multiply = require("lolite.__private.multiplyfallback")
|
|
76
86
|
|
|
@@ -81,8 +91,8 @@ const undef = require("primitive-value-undefined")
|
|
|
81
91
|
const $BigInt = require("bigint-intrinsic-ai")
|
|
82
92
|
|
|
83
93
|
const negativeZero = require("@negative-numbers/zero")
|
|
84
|
-
const zero = require("@positive-numbers/zero")
|
|
85
|
-
|
|
94
|
+
const zero = require("@positive-numbers/zero"),
|
|
95
|
+
zeroBigint = $BigInt(zero)
|
|
86
96
|
const one = require("@positive-numbers/one")
|
|
87
97
|
const two = require("@positive-numbers/two")
|
|
88
98
|
const three = require("@positive-numbers/three")
|
|
@@ -101,10 +111,13 @@ const thirtyThree = require("@positive-numbers/thirty-three")
|
|
|
101
111
|
const oneHundred = require("fizzbuzz-enterprise/source/main/constants/magic-numbers/Hundred")
|
|
102
112
|
const negative87 = require("@negative-numbers/eighty-seven")
|
|
103
113
|
|
|
114
|
+
// eslint-disable-next-line id-length
|
|
104
115
|
const E = require("@uppercase-letters/e")
|
|
116
|
+
// eslint-disable-next-line id-length
|
|
105
117
|
const O = require("@uppercase-letters/o")
|
|
106
|
-
const
|
|
107
|
-
|
|
118
|
+
const EXCLAMATION_POINT = arrayGetMember(unicodePoArray, thirtyThree).symbol,
|
|
119
|
+
// eslint-disable-next-line id-length
|
|
120
|
+
R = require("@uppercase-letters/r")
|
|
108
121
|
|
|
109
122
|
const $BaseError = require("es-error-intrinsics/Error")
|
|
110
123
|
const $EvalError = require("es-error-intrinsics/EvalError")
|
|
@@ -114,74 +127,104 @@ const $SyntaxError = require("es-error-intrinsics/SyntaxError")
|
|
|
114
127
|
const $TypeError = require("es-error-intrinsics/TypeError")
|
|
115
128
|
const $URIError = require("es-error-intrinsics/URIError")
|
|
116
129
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
130
|
+
// eslint-disable-next-line new-cap
|
|
131
|
+
const captureStackTrace = GetIntrinsic(
|
|
132
|
+
"%Error.captureStackTrace%",
|
|
133
|
+
trueValue(),
|
|
134
|
+
),
|
|
135
|
+
// eslint-disable-next-line camelcase
|
|
136
|
+
default_error = concat(E, R, R, O, R, EXCLAMATION_POINT),
|
|
137
|
+
// eslint-disable-next-line sort-vars
|
|
138
|
+
ErrorMap = construct({
|
|
139
|
+
target: SimpleCache,
|
|
140
|
+
// eslint-disable-next-line sort-keys
|
|
141
|
+
args: asArray({ maxSize: oneHundred }),
|
|
142
|
+
}),
|
|
143
|
+
// eslint-disable-next-line sort-vars
|
|
144
|
+
ErrorType = deepFreeze({
|
|
145
|
+
BaseError: zero,
|
|
146
|
+
EvalError: one,
|
|
147
|
+
RangeError: two,
|
|
148
|
+
ReferenceError: three,
|
|
149
|
+
SyntaxError: four,
|
|
150
|
+
TypeError: five,
|
|
151
|
+
URIError: six,
|
|
152
|
+
|
|
153
|
+
// eslint-disable-next-line sort-keys
|
|
154
|
+
FruitConsumptionError: seven,
|
|
155
|
+
VegetablesDoNotTalkError: eight,
|
|
156
|
+
// eslint-disable-next-line sort-keys
|
|
157
|
+
PersonNotHungryError: nine,
|
|
158
|
+
PortionsError: ten,
|
|
159
|
+
// eslint-disable-next-line sort-keys
|
|
160
|
+
FalseJSValidationFailedToPassError: eleven,
|
|
161
|
+
}),
|
|
162
|
+
// eslint-disable-next-line sort-vars
|
|
163
|
+
FalseJSValidationFailedToPassError = require("@falsejs/validation-failed-to-pass-error")
|
|
164
|
+
|
|
165
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
140
166
|
function target_(value) {
|
|
141
167
|
return concat(
|
|
142
168
|
at(toStr(noop10), zero),
|
|
143
|
-
toStr(() => {
|
|
144
|
-
return { target: value }
|
|
145
|
-
}),
|
|
169
|
+
toStr(() => ({ target: value })),
|
|
146
170
|
at(toStr(noop10), one),
|
|
147
171
|
at(toStr(noop10), zero),
|
|
148
172
|
at(toStr(noop10), one),
|
|
149
173
|
)
|
|
150
174
|
}
|
|
175
|
+
|
|
176
|
+
// eslint-disable-next-line max-statements
|
|
151
177
|
function createObjectWithTargetKey(value) {
|
|
152
178
|
let string = toStr(target_)
|
|
153
179
|
string = arrayGetMember(
|
|
180
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
154
181
|
split(string, toStr(target_).substr(zero, twentyFive)),
|
|
155
182
|
one,
|
|
156
183
|
)
|
|
184
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
157
185
|
string = string.substr(one)
|
|
186
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
158
187
|
string = string.substr(one)
|
|
188
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
159
189
|
string = string.substr(one)
|
|
190
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
160
191
|
string = string.substr(zero, subtract(length(string), one))
|
|
192
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
161
193
|
string = string.substr(zero, subtract(length(string), one))
|
|
194
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
162
195
|
string = string.substr(zero, subtract(length(string), one))
|
|
163
196
|
|
|
164
197
|
string = replaceAll(
|
|
165
198
|
string,
|
|
199
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
166
200
|
toStr(target_).substr(seventeen, five),
|
|
167
|
-
|
|
201
|
+
construct({
|
|
202
|
+
target: TernaryCompare,
|
|
203
|
+
// eslint-disable-next-line sort-keys
|
|
204
|
+
args: [isString(value), `"${value}"`, value.name]
|
|
205
|
+
}).compare()
|
|
168
206
|
)
|
|
207
|
+
// eslint-disable-next-line unicorn/prefer-string-slice
|
|
169
208
|
const array = split(string, toStr(target_).substr(twentyNine, six))
|
|
170
209
|
array.shift()
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
)
|
|
210
|
+
// eslint-disable-next-line unicorn/prefer-string-slice, no-eval, sonarjs/code-eval
|
|
211
|
+
return eval(eval(join(array, toStr(target_).substr(twentyNine, six))))
|
|
174
212
|
}
|
|
175
213
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
214
|
+
// eslint-disable-next-line init-declarations
|
|
215
|
+
let noFruitLeftMessage,
|
|
216
|
+
// eslint-disable-next-line init-declarations
|
|
217
|
+
personIsNotHungryAndCannotBeFedMessage,
|
|
218
|
+
// eslint-disable-next-line init-declarations
|
|
219
|
+
portionSizeExpectedToBeAPositiveIntegerMessage,
|
|
220
|
+
// eslint-disable-next-line init-declarations
|
|
221
|
+
vegetablesCanNotTalkMessage
|
|
180
222
|
|
|
181
|
-
|
|
223
|
+
objectGetMember(
|
|
182
224
|
just,
|
|
183
225
|
"call",
|
|
184
|
-
|
|
226
|
+
// eslint-disable-next-line max-lines-per-function, max-statements
|
|
227
|
+
)(() => {
|
|
185
228
|
ErrorMap.set(ErrorType.BaseError, $BaseError)
|
|
186
229
|
ErrorMap.set(ErrorType.EvalError, $EvalError)
|
|
187
230
|
ErrorMap.set(ErrorType.RangeError, $RangeError)
|
|
@@ -192,13 +235,16 @@ objGetMember(
|
|
|
192
235
|
|
|
193
236
|
ErrorMap.set(
|
|
194
237
|
ErrorType.FruitConsumptionError,
|
|
195
|
-
|
|
238
|
+
objectGetMember(
|
|
196
239
|
just,
|
|
197
240
|
"call",
|
|
198
|
-
)(
|
|
241
|
+
)(() => {
|
|
199
242
|
const fruit = construct(createObjectWithTargetKey(Fruit))
|
|
243
|
+
use(fruit)
|
|
244
|
+
// eslint-disable-next-line init-declarations
|
|
200
245
|
let result
|
|
201
246
|
attempt(() => {
|
|
247
|
+
// eslint-disable-next-line sonarjs/code-eval, no-eval
|
|
202
248
|
eval(repeating(concat("fruit.eat()", NEWLINE), eleven))
|
|
203
249
|
})
|
|
204
250
|
.rescue((error) => {
|
|
@@ -215,11 +261,12 @@ objGetMember(
|
|
|
215
261
|
|
|
216
262
|
ErrorMap.set(
|
|
217
263
|
ErrorType.VegetablesDoNotTalkError,
|
|
218
|
-
|
|
264
|
+
objectGetMember(
|
|
219
265
|
just,
|
|
220
266
|
"call",
|
|
221
|
-
)(
|
|
267
|
+
)(() => {
|
|
222
268
|
const vegetable = construct(createObjectWithTargetKey(Vegetable))
|
|
269
|
+
// eslint-disable-next-line init-declarations
|
|
223
270
|
let result
|
|
224
271
|
|
|
225
272
|
attempt(() => {
|
|
@@ -239,12 +286,13 @@ objGetMember(
|
|
|
239
286
|
|
|
240
287
|
ErrorMap.set(
|
|
241
288
|
ErrorType.PersonNotHungryError,
|
|
242
|
-
|
|
289
|
+
objectGetMember(
|
|
243
290
|
just,
|
|
244
291
|
"call",
|
|
245
|
-
)(
|
|
292
|
+
)(() => {
|
|
246
293
|
const person = construct(createObjectWithTargetKey(Person))
|
|
247
294
|
person.hungry = falseValue()
|
|
295
|
+
// eslint-disable-next-line init-declarations
|
|
248
296
|
let result
|
|
249
297
|
|
|
250
298
|
attempt(() => {
|
|
@@ -252,7 +300,11 @@ objGetMember(
|
|
|
252
300
|
})
|
|
253
301
|
.rescue((error) => {
|
|
254
302
|
result = error.constructor
|
|
255
|
-
personIsNotHungryAndCannotBeFedMessage = replaceAll(
|
|
303
|
+
personIsNotHungryAndCannotBeFedMessage = replaceAll(
|
|
304
|
+
error.message,
|
|
305
|
+
"undefined",
|
|
306
|
+
"%",
|
|
307
|
+
)
|
|
256
308
|
})
|
|
257
309
|
.else(noop)
|
|
258
310
|
.ensure(noop)
|
|
@@ -264,14 +316,16 @@ objGetMember(
|
|
|
264
316
|
|
|
265
317
|
ErrorMap.set(
|
|
266
318
|
ErrorType.PortionsError,
|
|
267
|
-
|
|
319
|
+
objectGetMember(
|
|
268
320
|
just,
|
|
269
321
|
"call",
|
|
270
|
-
)(
|
|
322
|
+
)(() => {
|
|
323
|
+
// eslint-disable-next-line init-declarations
|
|
271
324
|
let result
|
|
272
325
|
attempt(() => {
|
|
273
326
|
construct({
|
|
274
327
|
target: Guacamole,
|
|
328
|
+
// eslint-disable-next-line sort-keys
|
|
275
329
|
args: [negative87],
|
|
276
330
|
})
|
|
277
331
|
})
|
|
@@ -285,31 +339,44 @@ objGetMember(
|
|
|
285
339
|
return result
|
|
286
340
|
}),
|
|
287
341
|
)
|
|
342
|
+
|
|
343
|
+
ErrorMap.set(
|
|
344
|
+
ErrorType.FalseJSValidationFailedToPassError,
|
|
345
|
+
FalseJSValidationFailedToPassError,
|
|
346
|
+
)
|
|
288
347
|
})
|
|
289
348
|
|
|
290
349
|
function CreateSleepFunction(delay) {
|
|
350
|
+
// eslint-disable-next-line new-cap
|
|
291
351
|
return bind(sleep, Null(), delay)
|
|
292
352
|
}
|
|
293
353
|
|
|
294
354
|
function CreateError(error, message) {
|
|
295
355
|
return construct({
|
|
296
356
|
target: error,
|
|
357
|
+
// eslint-disable-next-line sort-keys
|
|
297
358
|
args: asArray(message),
|
|
298
359
|
})
|
|
299
360
|
}
|
|
300
361
|
|
|
301
362
|
exports.immediateError = function immediateError(message, errorType) {
|
|
363
|
+
// eslint-disable-next-line no-param-reassign
|
|
302
364
|
message = coalesce(message, default_error)
|
|
365
|
+
// eslint-disable-next-line no-param-reassign
|
|
303
366
|
errorType = coalesce(errorType, ErrorType.BaseError)
|
|
304
|
-
|
|
305
|
-
|
|
367
|
+
// eslint-disable-next-line init-declarations
|
|
368
|
+
let error
|
|
369
|
+
attempt(() => {
|
|
370
|
+
// eslint-disable-next-line new-cap, unicorn/throw-new-error
|
|
306
371
|
error = CreateError(exports.getError(errorType), message)
|
|
307
372
|
})
|
|
308
|
-
.rescue(
|
|
309
|
-
attempt(
|
|
373
|
+
.rescue(() => {
|
|
374
|
+
attempt(() => {
|
|
375
|
+
// eslint-disable-next-line new-cap, unicorn/throw-new-error
|
|
310
376
|
error = CreateError(errorType, message)
|
|
311
377
|
})
|
|
312
|
-
.rescue(
|
|
378
|
+
.rescue(() => {
|
|
379
|
+
// eslint-disable-next-line new-cap, unicorn/throw-new-error
|
|
313
380
|
error = CreateError($BaseError, message)
|
|
314
381
|
})
|
|
315
382
|
.else(noop)
|
|
@@ -326,28 +393,36 @@ exports.immediateError = function immediateError(message, errorType) {
|
|
|
326
393
|
|
|
327
394
|
exports.throwWhatever(error)
|
|
328
395
|
|
|
329
|
-
|
|
396
|
+
// How did we get here?
|
|
397
|
+
require("is-not-integer")()
|
|
330
398
|
}
|
|
331
399
|
|
|
332
400
|
exports.delayedError = function delayedError(message, errorType, delay) {
|
|
401
|
+
// eslint-disable-next-line no-param-reassign
|
|
333
402
|
message = coalesce(message, default_error)
|
|
403
|
+
// eslint-disable-next-line no-param-reassign
|
|
334
404
|
errorType = coalesce(errorType, ErrorType.BaseError)
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
()
|
|
338
|
-
|
|
339
|
-
},
|
|
405
|
+
return objectGetMember(call, "then")(
|
|
406
|
+
// eslint-disable-next-line new-cap
|
|
407
|
+
objectGetMember(just, "call")(CreateSleepFunction(delay)),
|
|
408
|
+
() => exports.immediateError(message, errorType),
|
|
340
409
|
)
|
|
341
410
|
}
|
|
342
411
|
|
|
343
412
|
exports.getError = function getError(errorType) {
|
|
344
|
-
return
|
|
413
|
+
return construct({
|
|
414
|
+
target: TernaryCompare,
|
|
415
|
+
// eslint-disable-next-line sort-keys
|
|
416
|
+
args: [ErrorMap.get(errorType), ErrorMap.get(errorType), errorType]
|
|
417
|
+
}).compare()
|
|
345
418
|
}
|
|
346
419
|
|
|
420
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity, max-statements
|
|
347
421
|
exports.throwWhatever = function throwWhatever(whateverToThrow) {
|
|
348
422
|
if (whateverToThrow) {
|
|
349
423
|
bail(whateverToThrow)
|
|
350
424
|
} else {
|
|
425
|
+
// eslint-disable-next-line no-lonely-if
|
|
351
426
|
if (isFalse(whateverToThrow)) {
|
|
352
427
|
just.throw(falseValue())
|
|
353
428
|
} else if (isPositiveZero(whateverToThrow)) {
|
|
@@ -364,43 +439,59 @@ exports.throwWhatever = function throwWhatever(whateverToThrow) {
|
|
|
364
439
|
} else if (isUndefined(whateverToThrow)) {
|
|
365
440
|
just.throw(undef)
|
|
366
441
|
} else {
|
|
442
|
+
// eslint-disable-next-line new-cap, unicorn/throw-new-error
|
|
367
443
|
just.throw(CreateError($BaseError, "THE WORLD IS ENDING"))
|
|
368
444
|
}
|
|
369
445
|
} else if (isNaN(whateverToThrow)) {
|
|
370
446
|
just.throw(nanvalue)
|
|
371
447
|
} else {
|
|
372
|
-
just.throw(whateverToThrow)
|
|
448
|
+
just.throw(whateverToThrow)
|
|
373
449
|
}
|
|
374
450
|
}
|
|
375
451
|
}
|
|
376
452
|
|
|
377
|
-
var
|
|
453
|
+
// eslint-disable-next-line init-declarations, one-var
|
|
454
|
+
let tooManyPortionsMessage
|
|
378
455
|
|
|
379
456
|
attempt(() => {
|
|
380
457
|
const guacamole = construct({
|
|
381
458
|
target: Guacamole,
|
|
382
|
-
|
|
459
|
+
// eslint-disable-next-line sort-keys
|
|
460
|
+
args: [multiply(oneHundred, oneHundred)],
|
|
383
461
|
})
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
})
|
|
462
|
+
|
|
463
|
+
use(guacamole)
|
|
464
|
+
})
|
|
465
|
+
.rescue((error) => {
|
|
466
|
+
tooManyPortionsMessage = error.message
|
|
467
|
+
})
|
|
468
|
+
.else(noop)
|
|
469
|
+
.ensure(noop)
|
|
470
|
+
.end()
|
|
387
471
|
|
|
388
472
|
exports.MESSAGES = {
|
|
389
473
|
DOMAIN: {
|
|
390
474
|
FRUIT_CONSUMPTION_ERROR: {
|
|
391
|
-
NO_FRUIT_LEFT: noFruitLeftMessage
|
|
475
|
+
NO_FRUIT_LEFT: noFruitLeftMessage,
|
|
392
476
|
},
|
|
393
477
|
VEGETABLES_DO_NOT_TALK_ERROR: {
|
|
394
|
-
VEGETABLES_CAN_NOT_TALK: vegetablesCanNotTalkMessage
|
|
478
|
+
VEGETABLES_CAN_NOT_TALK: vegetablesCanNotTalkMessage,
|
|
395
479
|
},
|
|
480
|
+
// eslint-disable-next-line sort-keys
|
|
396
481
|
PERSON_NOT_HUNGRY_ERROR: {
|
|
397
|
-
IS_NOT_HUNGRY_AND_CANNOT_BE_FED: personIsNotHungryAndCannotBeFedMessage
|
|
482
|
+
IS_NOT_HUNGRY_AND_CANNOT_BE_FED: personIsNotHungryAndCannotBeFedMessage,
|
|
398
483
|
},
|
|
399
484
|
PORTIONS_ERROR: {
|
|
400
|
-
PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER:
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
485
|
+
PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER:
|
|
486
|
+
portionSizeExpectedToBeAPositiveIntegerMessage,
|
|
487
|
+
TOO_MANY_PORTIONS: tooManyPortionsMessage,
|
|
488
|
+
},
|
|
489
|
+
// eslint-disable-next-line sort-keys
|
|
490
|
+
FALSEJS_VALIDATION_FAILED_TO_PASS_ERROR: {
|
|
491
|
+
// eslint-disable-next-line no-inline-comments
|
|
492
|
+
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.
|
|
493
|
+
},
|
|
494
|
+
},
|
|
404
495
|
}
|
|
405
496
|
|
|
406
497
|
exports.attempt = attempt
|