immediate-error 12.1.0 → 12.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
@@ -34,7 +34,7 @@ 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 cannot talk error", ErrorType.VegetablesCannotTalkError) // throws a VegetablesCannotTalkError
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
 
@@ -61,7 +61,7 @@ const TypeErrorConstructor = getError(ErrorType.TypeError)
61
61
 
62
62
  console.log(TypeErrorConstructor === TypeError) // true
63
63
 
64
- const VegetablesCannotTalkError = getError(ErrorType.VegetablesCannotTalkError)
64
+ const VegetablesDoNotTalkError = getError(ErrorType.VegetablesDoNotTalkError)
65
65
 
66
66
  try {
67
67
  const Vegetable = require("libvegetable")
@@ -69,7 +69,7 @@ try {
69
69
 
70
70
  vegetable.greet()
71
71
  } catch (error) {
72
- console.log(error.constructor === VegetablesCannotTalkError) // true
72
+ console.log(error.constructor === VegetablesDoNotTalkError) // true
73
73
  }
74
74
  ```
75
75
 
@@ -98,6 +98,17 @@ const { delayedError, ErrorType } = require("immediate-error")
98
98
  delayedError("delayed", ErrorType.BaseError, 1000) // waits 1000 ms (1 second) and then throws error
99
99
  ```
100
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
+
101
112
  ## `immediate-error` 2.0.0
102
113
 
103
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:
@@ -116,6 +127,25 @@ throwErrorWithMessage("Test") // throws an error with message Test
116
127
 
117
128
  It always throws a base error with the message passed in.
118
129
 
119
-
120
130
  ## License
121
- Unlicense
131
+ [EGPSL10X-1.0](https://github.com/10xly/licence)
132
+
133
+ ## Code Of Conduct
134
+ [10xly Lolite Code Of Conduct](https://github.com/10xly/lolite/blob/main/CODE_OF_CONDUCT.md)
135
+
136
+ ## Legal
137
+ [Legal](https://github.com/10xly/legal)
138
+
139
+ ## One thing
140
+
141
+ While your wasting your valuable time using this very useful package, I'd like to make some things clear:
142
+
143
+ 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.
144
+
145
+ Sources:
146
+ - [libperson](https://npmjs.com/package/libperson?activeTab=code)
147
+ - [libvegetable](https://npmjs.com/package/libvegetable?activeTab=code)
148
+ - [jsfruit](https://npmjs.com/package/jsfruit?activeTab=code)
149
+ - [libguacamole](https://npmjs.com/package/libguacamole?activeTab=code)
150
+
151
+ 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,
@@ -7,71 +8,76 @@ export enum ErrorType {
7
8
  TypeError = 5,
8
9
  URIError = 6,
9
10
  FruitConsumptionError = 7,
10
- VegetablesCannotTalkError = 8,
11
+ VegetablesDoNotTalkError = 8,
11
12
  PersonNotHungryError = 9,
12
- PortionsError = 10
13
+ PortionsError = 10,
13
14
  }
14
-
15
15
  export type CustomError = {
16
16
  new (message: string): Error
17
17
  }
18
-
19
18
  export function getError(errorType: ErrorType.BaseError): typeof Error
20
19
  export function getError(errorType: ErrorType.EvalError): typeof EvalError
21
20
  export function getError(errorType: ErrorType.RangeError): typeof RangeError
22
21
  export function getError(
23
- errorType: ErrorType.ReferenceError
22
+ errorType: ErrorType.ReferenceError,
24
23
  ): typeof ReferenceError
25
24
  export function getError(errorType: ErrorType.SyntaxError): typeof SyntaxError
26
25
  export function getError(errorType: ErrorType.TypeError): typeof TypeError
27
26
  export function getError(errorType: ErrorType.URIError): typeof URIError
28
27
  export function getError(
29
- errorType: ErrorType.FruitConsumptionError
28
+ errorType: ErrorType.FruitConsumptionError,
30
29
  ): CustomError
31
30
  export function getError(
32
- errorType: ErrorType.VegetablesCannotTalkError
31
+ errorType: ErrorType.VegetablesDoNotTalkError,
33
32
  ): CustomError
34
33
  export function getError(errorType: ErrorType.PersonNotHungryError): CustomError
35
34
  export function getError(errorType: ErrorType.PortionsError): CustomError
36
35
  export function getError(errorType: ErrorType | CustomError): CustomError
37
-
38
36
  export function immediateError(
39
37
  message?: string,
40
- errorType?: ErrorType | CustomError
38
+ errorType?: ErrorType | CustomError,
41
39
  ): never
42
-
43
40
  export function throwWhatever(whateverToThrow: any): never
44
-
45
- interface AttemptConstructor {
46
- new (handler?: () => void): Attempt
47
-
48
- (handler?: () => void): Attempt
41
+ export const attempt: {
42
+ new (handler?: () => void): {
43
+ trycode?: () => void
44
+ rescuehandler?: (error: any) => void
45
+ elsehandler?: () => void
46
+ ensurehandler?: (error: any) => void
47
+ rescue(handler: (error: any) => void): this
48
+ else(handler: () => void): this
49
+ ensure(handler: () => void): this
50
+ end(): void
51
+ }
52
+ (handler?: () => void): {
53
+ trycode?: () => void
54
+ rescuehandler?: (error: any) => void
55
+ elsehandler?: () => void
56
+ ensurehandler?: (error: any) => void
57
+ rescue(handler: (error: any) => void): this
58
+ else(handler: () => void): this
59
+ ensure(handler: () => void): this
60
+ end(): void
61
+ }
49
62
  }
50
-
51
- declare class Attempt {
52
- constructor(handler?: () => void)
53
-
54
- trycode?: () => void
55
- rescuehandler?: (error: any) => void
56
- elsehandler?: () => void
57
- ensurehandler?: (error: any) => void
58
-
59
- rescue(handler: (error: any) => void): this
60
- else(handler: () => void): this
61
- ensure(handler: () => void): this
62
- end(): void
63
- }
64
-
65
- export const attempt: AttemptConstructor
66
-
67
63
  export function delayedError(
68
64
  message?: string,
69
65
  errorType?: ErrorType | CustomError,
70
- delay?: number
66
+ delay?: number,
71
67
  ): Promise<never>
72
68
 
73
- export function delayedError(
74
- message: undefined,
75
- errorType: undefined,
76
- delay: number
77
- ): Promise<never>
69
+ export const MESSAGES: {
70
+ DOMAIN: {
71
+ FRUIT_CONSUMPTION_ERROR: { NO_FRUIT_LEFT: "no fruit left" }
72
+ VEGETABLES_DO_NOT_TALK_ERROR: {
73
+ VEGETABLES_CAN_NOT_TALK: "vegetables can not talk"
74
+ }
75
+ PERSON_NOT_HUNGRY_ERROR: {
76
+ IS_NOT_HUNGRY_AND_CANNOT_BE_FED: "% is not hungry and cannot be fed"
77
+ },
78
+ PORTIONS_ERROR: {
79
+ PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: "Portion size expected to be a positive integer",
80
+ TOO_MANY_PORTIONS: "Too many portions"
81
+ }
82
+ }
83
+ }
package/index.js CHANGED
@@ -3,10 +3,10 @@
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
- eval(require("javascript-interpreter"))
9
- let interpret = require("javascript-interpreter/interpret")
10
10
  const Fruit = require("jsfruit")
11
11
  const Vegetable = require("libvegetable")
12
12
  const Person = require("libperson")
@@ -20,7 +20,7 @@ const construct = require("construct-new")
20
20
  const toStr = require("@rightpad/convert2string")
21
21
  const attempt = require("attempt-statement")
22
22
  const trueValue = require("true-value")
23
- const asArray = require("as-array")
23
+ const asArray = x => [x] // behind bars
24
24
  const isString = require("@is-(unknown)/is-string")
25
25
  const repeating = require("repeating")
26
26
  const deepFreeze = require("deep-freeze-node3") // 3rd iteration of deep-freeze-node, and the only 10x one.
@@ -72,6 +72,8 @@ const isNull = require("@is-(unknown)/is-null")
72
72
  const isUndefined = require("@is-(unknown)/is-undefined")
73
73
  const isNaN = require("@is-(unknown)/is-nan")
74
74
 
75
+ const multiply = require("lolite.__private.multiplyfallback")
76
+
75
77
  const nullvalue = require("primitive-value-null")
76
78
  const nanvalue = require("primitive-value-nan")
77
79
  const undef = require("primitive-value-undefined")
@@ -125,7 +127,7 @@ const ErrorType = deepFreeze({
125
127
  URIError: six,
126
128
 
127
129
  FruitConsumptionError: seven,
128
- VegetablesCannotTalkError: eight,
130
+ VegetablesDoNotTalkError: eight,
129
131
  PersonNotHungryError: nine,
130
132
  PortionsError: ten,
131
133
  })
@@ -166,13 +168,16 @@ function createObjectWithTargetKey(value) {
166
168
  )
167
169
  const array = split(string, toStr(target_).substr(twentyNine, six))
168
170
  array.shift()
169
- eval(require("javascript-interpreter"))
170
- interpret = require("javascript-interpreter/interpret")
171
- return interpret(
172
- interpret(join(array, toStr(target_).substr(twentyNine, six))),
171
+ return eval(
172
+ eval(join(array, toStr(target_).substr(twentyNine, six))),
173
173
  )
174
174
  }
175
175
 
176
+ var noFruitLeftMessage
177
+ var vegetablesCanNotTalkMessage
178
+ var personIsNotHungryAndCannotBeFedMessage
179
+ var portionSizeExpectedToBeAPositiveIntegerMessage
180
+
176
181
  objGetMember(
177
182
  just,
178
183
  "call",
@@ -194,14 +199,11 @@ objGetMember(
194
199
  const fruit = construct(createObjectWithTargetKey(Fruit))
195
200
  let result
196
201
  attempt(() => {
197
- fruit
198
- eval(require("javascript-interpreter"))
199
- interpret = require("javascript-interpreter/interpret")
200
-
201
- interpret(repeating(concat("fruit.eat()", NEWLINE), eleven))
202
+ eval(repeating(concat("fruit.eat()", NEWLINE), eleven))
202
203
  })
203
204
  .rescue((error) => {
204
205
  result = error.constructor
206
+ noFruitLeftMessage = error.message
205
207
  })
206
208
  .else(noop)
207
209
  .ensure(noop)
@@ -212,7 +214,7 @@ objGetMember(
212
214
  )
213
215
 
214
216
  ErrorMap.set(
215
- ErrorType.VegetablesCannotTalkError,
217
+ ErrorType.VegetablesDoNotTalkError,
216
218
  objGetMember(
217
219
  just,
218
220
  "call",
@@ -225,6 +227,7 @@ objGetMember(
225
227
  })
226
228
  .rescue((error) => {
227
229
  result = error.constructor
230
+ vegetablesCanNotTalkMessage = error.message
228
231
  })
229
232
  .else(noop)
230
233
  .ensure(noop)
@@ -249,6 +252,7 @@ objGetMember(
249
252
  })
250
253
  .rescue((error) => {
251
254
  result = error.constructor
255
+ personIsNotHungryAndCannotBeFedMessage = replaceAll(error.message, "undefined", "%")
252
256
  })
253
257
  .else(noop)
254
258
  .ensure(noop)
@@ -273,6 +277,7 @@ objGetMember(
273
277
  })
274
278
  .rescue((error) => {
275
279
  result = error.constructor
280
+ portionSizeExpectedToBeAPositiveIntegerMessage = error.message
276
281
  })
277
282
  .else(noop)
278
283
  .ensure(noop)
@@ -369,6 +374,35 @@ exports.throwWhatever = function throwWhatever(whateverToThrow) {
369
374
  }
370
375
  }
371
376
 
377
+ var tooManyPortionsMessage
378
+
379
+ attempt(() => {
380
+ const guacamole = construct({
381
+ target: Guacamole,
382
+ args: [multiply(oneHundred, oneHundred)]
383
+ })
384
+ }).rescue(error => {
385
+ tooManyPortionsMessage = error.message
386
+ }).else(noop).ensure(noop).end()
387
+
388
+ exports.MESSAGES = {
389
+ DOMAIN: {
390
+ FRUIT_CONSUMPTION_ERROR: {
391
+ NO_FRUIT_LEFT: noFruitLeftMessage
392
+ },
393
+ VEGETABLES_DO_NOT_TALK_ERROR: {
394
+ VEGETABLES_CAN_NOT_TALK: vegetablesCanNotTalkMessage
395
+ },
396
+ PERSON_NOT_HUNGRY_ERROR: {
397
+ IS_NOT_HUNGRY_AND_CANNOT_BE_FED: personIsNotHungryAndCannotBeFedMessage
398
+ },
399
+ PORTIONS_ERROR: {
400
+ PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER: portionSizeExpectedToBeAPositiveIntegerMessage,
401
+ TOO_MANY_PORTIONS: tooManyPortionsMessage
402
+ }
403
+ }
404
+ }
405
+
372
406
  exports.attempt = attempt
373
407
 
374
408
  exports.ErrorType = ErrorType
package/index.test.js CHANGED
@@ -1,8 +1,11 @@
1
+ // tests
2
+
1
3
  const {
2
4
  immediateError,
3
5
  ErrorType,
4
6
  throwWhatever,
5
7
  getError,
8
+ MESSAGES
6
9
  } = require("./index")
7
10
 
8
11
  describe("immediateError utility", () => {
@@ -24,16 +27,16 @@ describe("immediateError utility", () => {
24
27
  ["SyntaxError", ErrorType.SyntaxError, SyntaxError],
25
28
  ["TypeError", ErrorType.TypeError, TypeError],
26
29
  ["URIError", ErrorType.URIError, URIError],
27
- ])("throws %s when specified", (name, type, constructor) => {
30
+ ])("throws % when specified", (name, type, constructor) => {
28
31
  expect(() => immediateError("test message", type)).toThrow(constructor)
29
32
  })
30
33
 
31
34
  test.each([
32
35
  ["FruitConsumptionError", ErrorType.FruitConsumptionError],
33
- ["VegetablesCannotTalkError", ErrorType.VegetablesCannotTalkError],
36
+ ["VegetablesDoNotTalkError", ErrorType.VegetablesDoNotTalkError],
34
37
  ["PersonNotHungryError", ErrorType.PersonNotHungryError],
35
38
  ["PortionsError", ErrorType.PortionsError],
36
- ])("throws domain-specific %s correctly", (name, type) => {
39
+ ])("throws domain-specific % correctly", (name, type) => {
37
40
  const expectedConstructor = getError(type)
38
41
  expect(() => immediateError("enterprise failure", type)).toThrow(expectedConstructor)
39
42
  expect(() => immediateError("enterprise failure", type)).toThrow("enterprise failure")
@@ -240,3 +243,15 @@ describe("getError utility", () => {
240
243
  expect(result).toBe(MyError)
241
244
  })
242
245
  })
246
+
247
+ describe("error messages", () => {
248
+ test.each([
249
+ ["no fruit left", MESSAGES.DOMAIN.FRUIT_CONSUMPTION_ERROR.NO_FRUIT_LEFT],
250
+ ["vegetables can not talk", MESSAGES.DOMAIN.VEGETABLES_DO_NOT_TALK_ERROR.VEGETABLES_CAN_NOT_TALK],
251
+ ["% is not hungry and cannot be fed", MESSAGES.DOMAIN.PERSON_NOT_HUNGRY_ERROR.IS_NOT_HUNGRY_AND_CANNOT_BE_FED],
252
+ ["Portion size expected to be a positive integer", MESSAGES.DOMAIN.PORTIONS_ERROR.PORTION_SIZE_EXPECTED_TO_BE_A_POSITIVE_INTEGER],
253
+ ["Too many portions", MESSAGES.DOMAIN.PORTIONS_ERROR.TOO_MANY_PORTIONS]
254
+ ])("provides error message \"%s\" correctly", (a, b) => {
255
+ expect(a).toEqual(b)
256
+ })
257
+ })
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,6 +1,6 @@
1
1
  {
2
2
  "name": "immediate-error",
3
- "version": "12.1.0",
3
+ "version": "12.2.1",
4
4
  "description": "enterprise errors",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,7 +43,7 @@
43
43
  "stevelib"
44
44
  ],
45
45
  "author": "10x'ly Made",
46
- "license": "Unlicense",
46
+ "license": "EGPSL10X-1.0",
47
47
  "bugs": {
48
48
  "url": "https://github.com/enterprise-npm-ai/immediate-error/issues"
49
49
  },
@@ -84,14 +84,13 @@
84
84
  "@uppercase-letters/e": "^3.0.0",
85
85
  "@uppercase-letters/o": "^3.0.0",
86
86
  "@uppercase-letters/r": "^3.0.0",
87
- "array-get-member": "^1.0.3",
87
+ "array-get-member": "^1.0.4",
88
88
  "array.prototype.join": "^1.0.4",
89
- "as-array": "^2.0.0",
90
89
  "attempt-statement": "^1.2.1",
91
90
  "bail": "^1.0.5",
92
91
  "basic-functions": "^1.0.6",
93
92
  "bigint-intrinsic-ai": "1.0.0",
94
- "construct-new": "^2.0.3",
93
+ "construct-new": "^2.0.8",
95
94
  "deep-freeze-node3": "^1.1.0",
96
95
  "empty-string": "1.1.1",
97
96
  "es-error-intrinsics": "^1.0.1",
@@ -104,13 +103,14 @@
104
103
  "get-member": "^1337.69.420",
105
104
  "is-": "^1.0.0",
106
105
  "is-not-integer": "^1.0.2",
107
- "javascript-interpreter": "^1.0.0",
108
106
  "jsfruit": "^1.1.0",
109
107
  "libguacamole": "^1.0.0",
110
108
  "libperson": "^1.0.0",
111
109
  "libvegetable": "^1.0.0",
112
110
  "lodash.stubarray": "^4.13.0",
111
+ "lolite.__private.multiplyfallback": "^1.1.17",
113
112
  "node-call.then": "^1.0.0",
113
+ "none": "^1.0.0",
114
114
  "noop-enterprise": "^2.0.1",
115
115
  "noop10": "1.0.3",
116
116
  "numero": "^0.1.1",