apcore-js 0.3.0 → 0.5.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/.github/workflows/ci.yml +39 -0
- package/CHANGELOG.md +70 -0
- package/package.json +4 -2
- package/src/acl.ts +21 -8
- package/src/async-task.ts +267 -0
- package/src/bindings.ts +6 -0
- package/src/cancel.ts +32 -0
- package/src/context.ts +87 -2
- package/src/errors.ts +7 -2
- package/src/executor.ts +35 -9
- package/src/extensions.ts +265 -0
- package/src/index.ts +18 -4
- package/src/middleware/manager.ts +1 -1
- package/src/observability/context-logger.ts +4 -2
- package/src/observability/metrics.ts +4 -2
- package/src/observability/tracing.ts +73 -8
- package/src/registry/index.ts +1 -0
- package/src/registry/registry.ts +229 -5
- package/src/registry/scanner.ts +28 -10
- package/src/registry/schema-export.ts +10 -3
- package/src/schema/loader.ts +29 -15
- package/src/schema/ref-resolver.ts +14 -2
- package/src/schema/strict.ts +11 -1
- package/src/trace-context.ts +102 -0
- package/tests/async-task.test.ts +335 -0
- package/tests/integration/test-acl-safety.test.ts +2 -1
- package/tests/observability/test-metrics.test.ts +98 -1
- package/tests/observability/test-tracing.test.ts +173 -1
- package/tests/registry/test-registry.test.ts +1258 -1
- package/tests/registry/test-schema-export.test.ts +131 -1
- package/tests/schema/test-loader.test.ts +366 -2
- package/tests/schema/test-ref-resolver.test.ts +427 -2
- package/tests/schema/test-strict.test.ts +209 -0
- package/tests/test-acl.test.ts +218 -1
- package/tests/test-cancel.test.ts +71 -0
- package/tests/test-context.test.ts +115 -0
- package/tests/test-errors.test.ts +448 -5
- package/tests/test-extensions.test.ts +310 -0
- package/tests/test-trace-context.test.ts +251 -0
- package/tests/utils/test-pattern.test.ts +109 -0
|
@@ -3,14 +3,23 @@ import {
|
|
|
3
3
|
ModuleError,
|
|
4
4
|
ModuleNotFoundError,
|
|
5
5
|
ModuleTimeoutError,
|
|
6
|
+
ModuleExecuteError,
|
|
7
|
+
ModuleLoadError,
|
|
6
8
|
SchemaValidationError,
|
|
9
|
+
SchemaNotFoundError,
|
|
10
|
+
SchemaParseError,
|
|
11
|
+
SchemaCircularRefError,
|
|
7
12
|
ACLDeniedError,
|
|
13
|
+
ACLRuleError,
|
|
8
14
|
CallDepthExceededError,
|
|
9
15
|
CircularCallError,
|
|
10
16
|
CallFrequencyExceededError,
|
|
11
17
|
ConfigNotFoundError,
|
|
12
18
|
ConfigError,
|
|
13
19
|
InvalidInputError,
|
|
20
|
+
InternalError,
|
|
21
|
+
FuncMissingTypeHintError,
|
|
22
|
+
FuncMissingReturnTypeError,
|
|
14
23
|
BindingInvalidTargetError,
|
|
15
24
|
BindingModuleNotFoundError,
|
|
16
25
|
BindingCallableNotFoundError,
|
|
@@ -18,11 +27,7 @@ import {
|
|
|
18
27
|
BindingSchemaMissingError,
|
|
19
28
|
BindingFileInvalidError,
|
|
20
29
|
CircularDependencyError,
|
|
21
|
-
|
|
22
|
-
SchemaNotFoundError,
|
|
23
|
-
SchemaParseError,
|
|
24
|
-
SchemaCircularRefError,
|
|
25
|
-
ACLRuleError,
|
|
30
|
+
ErrorCodes,
|
|
26
31
|
} from '../src/errors.js';
|
|
27
32
|
|
|
28
33
|
describe('ModuleError', () => {
|
|
@@ -202,3 +207,441 @@ describe('Error subclasses', () => {
|
|
|
202
207
|
expect(err.code).toBe('ACL_RULE_ERROR');
|
|
203
208
|
});
|
|
204
209
|
});
|
|
210
|
+
|
|
211
|
+
describe('ModuleError optional parameters', () => {
|
|
212
|
+
it('defaults details to empty object when not provided', () => {
|
|
213
|
+
const err = new ModuleError('X', 'msg');
|
|
214
|
+
expect(err.details).toEqual({});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('leaves cause and traceId undefined when not provided', () => {
|
|
218
|
+
const err = new ModuleError('X', 'msg');
|
|
219
|
+
expect(err.cause).toBeUndefined();
|
|
220
|
+
expect(err.traceId).toBeUndefined();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('passes cause to Error super constructor', () => {
|
|
224
|
+
const cause = new Error('root');
|
|
225
|
+
const err = new ModuleError('X', 'msg', {}, cause);
|
|
226
|
+
expect(err.cause).toBe(cause);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('sets traceId when provided', () => {
|
|
230
|
+
const err = new ModuleError('X', 'msg', {}, undefined, 'trace-abc');
|
|
231
|
+
expect(err.traceId).toBe('trace-abc');
|
|
232
|
+
expect(err.cause).toBeUndefined();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('toString returns formatted code and message', () => {
|
|
236
|
+
const err = new ModuleError('MY_CODE', 'my message');
|
|
237
|
+
expect(err.toString()).toBe('[MY_CODE] my message');
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('Error subclasses with options (cause and traceId branches)', () => {
|
|
242
|
+
const cause = new Error('underlying cause');
|
|
243
|
+
const traceId = 'trace-999';
|
|
244
|
+
|
|
245
|
+
it('ConfigNotFoundError with cause and traceId', () => {
|
|
246
|
+
const err = new ConfigNotFoundError('/cfg', { cause, traceId });
|
|
247
|
+
expect(err.cause).toBe(cause);
|
|
248
|
+
expect(err.traceId).toBe(traceId);
|
|
249
|
+
expect(err.details['configPath']).toBe('/cfg');
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('ConfigNotFoundError without options', () => {
|
|
253
|
+
const err = new ConfigNotFoundError('/cfg');
|
|
254
|
+
expect(err.cause).toBeUndefined();
|
|
255
|
+
expect(err.traceId).toBeUndefined();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('ConfigError with cause and traceId', () => {
|
|
259
|
+
const err = new ConfigError('bad config', { cause, traceId });
|
|
260
|
+
expect(err.cause).toBe(cause);
|
|
261
|
+
expect(err.traceId).toBe(traceId);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('ConfigError without options', () => {
|
|
265
|
+
const err = new ConfigError('bad config');
|
|
266
|
+
expect(err.cause).toBeUndefined();
|
|
267
|
+
expect(err.traceId).toBeUndefined();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('ACLRuleError with cause and traceId', () => {
|
|
271
|
+
const err = new ACLRuleError('bad rule', { cause, traceId });
|
|
272
|
+
expect(err.cause).toBe(cause);
|
|
273
|
+
expect(err.traceId).toBe(traceId);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('ACLRuleError without options', () => {
|
|
277
|
+
const err = new ACLRuleError('bad rule');
|
|
278
|
+
expect(err.cause).toBeUndefined();
|
|
279
|
+
expect(err.traceId).toBeUndefined();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('ACLDeniedError with cause and traceId', () => {
|
|
283
|
+
const err = new ACLDeniedError('caller.a', 'target.b', { cause, traceId });
|
|
284
|
+
expect(err.cause).toBe(cause);
|
|
285
|
+
expect(err.traceId).toBe(traceId);
|
|
286
|
+
expect(err.callerId).toBe('caller.a');
|
|
287
|
+
expect(err.targetId).toBe('target.b');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('ACLDeniedError without options', () => {
|
|
291
|
+
const err = new ACLDeniedError('caller.a', 'target.b');
|
|
292
|
+
expect(err.cause).toBeUndefined();
|
|
293
|
+
expect(err.traceId).toBeUndefined();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('ACLDeniedError with null callerId', () => {
|
|
297
|
+
const err = new ACLDeniedError(null, 'target.b');
|
|
298
|
+
expect(err.callerId).toBeNull();
|
|
299
|
+
expect(err.targetId).toBe('target.b');
|
|
300
|
+
expect(err.message).toContain('null -> target.b');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('ModuleNotFoundError with cause and traceId', () => {
|
|
304
|
+
const err = new ModuleNotFoundError('mod.x', { cause, traceId });
|
|
305
|
+
expect(err.cause).toBe(cause);
|
|
306
|
+
expect(err.traceId).toBe(traceId);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('ModuleNotFoundError without options', () => {
|
|
310
|
+
const err = new ModuleNotFoundError('mod.x');
|
|
311
|
+
expect(err.cause).toBeUndefined();
|
|
312
|
+
expect(err.traceId).toBeUndefined();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('ModuleTimeoutError with cause and traceId', () => {
|
|
316
|
+
const err = new ModuleTimeoutError('mod.x', 3000, { cause, traceId });
|
|
317
|
+
expect(err.cause).toBe(cause);
|
|
318
|
+
expect(err.traceId).toBe(traceId);
|
|
319
|
+
expect(err.moduleId).toBe('mod.x');
|
|
320
|
+
expect(err.timeoutMs).toBe(3000);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('ModuleTimeoutError without options', () => {
|
|
324
|
+
const err = new ModuleTimeoutError('mod.x', 3000);
|
|
325
|
+
expect(err.cause).toBeUndefined();
|
|
326
|
+
expect(err.traceId).toBeUndefined();
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('SchemaValidationError with cause and traceId', () => {
|
|
330
|
+
const err = new SchemaValidationError('invalid', [{ path: '/a' }], { cause, traceId });
|
|
331
|
+
expect(err.cause).toBe(cause);
|
|
332
|
+
expect(err.traceId).toBe(traceId);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('SchemaValidationError without options', () => {
|
|
336
|
+
const err = new SchemaValidationError('invalid', []);
|
|
337
|
+
expect(err.cause).toBeUndefined();
|
|
338
|
+
expect(err.traceId).toBeUndefined();
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('SchemaValidationError uses default message when no arguments provided', () => {
|
|
342
|
+
const err = new SchemaValidationError();
|
|
343
|
+
expect(err.message).toBe('Schema validation failed');
|
|
344
|
+
expect(err.details['errors']).toEqual([]);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('SchemaValidationError defaults errors to empty array when errors not provided', () => {
|
|
348
|
+
const err = new SchemaValidationError('custom message');
|
|
349
|
+
expect(err.details['errors']).toEqual([]);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('SchemaNotFoundError with cause and traceId', () => {
|
|
353
|
+
const err = new SchemaNotFoundError('schema.x', { cause, traceId });
|
|
354
|
+
expect(err.cause).toBe(cause);
|
|
355
|
+
expect(err.traceId).toBe(traceId);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('SchemaNotFoundError without options', () => {
|
|
359
|
+
const err = new SchemaNotFoundError('schema.x');
|
|
360
|
+
expect(err.cause).toBeUndefined();
|
|
361
|
+
expect(err.traceId).toBeUndefined();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('SchemaParseError with cause and traceId', () => {
|
|
365
|
+
const err = new SchemaParseError('bad yaml', { cause, traceId });
|
|
366
|
+
expect(err.cause).toBe(cause);
|
|
367
|
+
expect(err.traceId).toBe(traceId);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('SchemaParseError without options', () => {
|
|
371
|
+
const err = new SchemaParseError('bad yaml');
|
|
372
|
+
expect(err.cause).toBeUndefined();
|
|
373
|
+
expect(err.traceId).toBeUndefined();
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('SchemaCircularRefError with cause and traceId', () => {
|
|
377
|
+
const err = new SchemaCircularRefError('#/defs/A', { cause, traceId });
|
|
378
|
+
expect(err.cause).toBe(cause);
|
|
379
|
+
expect(err.traceId).toBe(traceId);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('SchemaCircularRefError without options', () => {
|
|
383
|
+
const err = new SchemaCircularRefError('#/defs/A');
|
|
384
|
+
expect(err.cause).toBeUndefined();
|
|
385
|
+
expect(err.traceId).toBeUndefined();
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('CallDepthExceededError with cause and traceId', () => {
|
|
389
|
+
const err = new CallDepthExceededError(5, 4, ['a', 'b'], { cause, traceId });
|
|
390
|
+
expect(err.cause).toBe(cause);
|
|
391
|
+
expect(err.traceId).toBe(traceId);
|
|
392
|
+
expect(err.currentDepth).toBe(5);
|
|
393
|
+
expect(err.maxDepth).toBe(4);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('CallDepthExceededError without options', () => {
|
|
397
|
+
const err = new CallDepthExceededError(5, 4, ['a', 'b']);
|
|
398
|
+
expect(err.cause).toBeUndefined();
|
|
399
|
+
expect(err.traceId).toBeUndefined();
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('CircularCallError with cause and traceId', () => {
|
|
403
|
+
const err = new CircularCallError('mod.a', ['mod.a', 'mod.b'], { cause, traceId });
|
|
404
|
+
expect(err.cause).toBe(cause);
|
|
405
|
+
expect(err.traceId).toBe(traceId);
|
|
406
|
+
expect(err.moduleId).toBe('mod.a');
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it('CircularCallError without options', () => {
|
|
410
|
+
const err = new CircularCallError('mod.a', ['mod.a', 'mod.b']);
|
|
411
|
+
expect(err.cause).toBeUndefined();
|
|
412
|
+
expect(err.traceId).toBeUndefined();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('CallFrequencyExceededError with cause and traceId', () => {
|
|
416
|
+
const err = new CallFrequencyExceededError('mod.a', 4, 3, ['mod.a'], { cause, traceId });
|
|
417
|
+
expect(err.cause).toBe(cause);
|
|
418
|
+
expect(err.traceId).toBe(traceId);
|
|
419
|
+
expect(err.moduleId).toBe('mod.a');
|
|
420
|
+
expect(err.count).toBe(4);
|
|
421
|
+
expect(err.maxRepeat).toBe(3);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it('CallFrequencyExceededError without options', () => {
|
|
425
|
+
const err = new CallFrequencyExceededError('mod.a', 4, 3, ['mod.a']);
|
|
426
|
+
expect(err.cause).toBeUndefined();
|
|
427
|
+
expect(err.traceId).toBeUndefined();
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it('InvalidInputError with cause and traceId', () => {
|
|
431
|
+
const err = new InvalidInputError('bad data', { cause, traceId });
|
|
432
|
+
expect(err.cause).toBe(cause);
|
|
433
|
+
expect(err.traceId).toBe(traceId);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('InvalidInputError without options', () => {
|
|
437
|
+
const err = new InvalidInputError('bad data');
|
|
438
|
+
expect(err.cause).toBeUndefined();
|
|
439
|
+
expect(err.traceId).toBeUndefined();
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it('InvalidInputError uses default message when no arguments provided', () => {
|
|
443
|
+
const err = new InvalidInputError();
|
|
444
|
+
expect(err.message).toBe('Invalid input');
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('FuncMissingTypeHintError with cause and traceId', () => {
|
|
448
|
+
const err = new FuncMissingTypeHintError('myFunc', 'myParam', { cause, traceId });
|
|
449
|
+
expect(err.name).toBe('FuncMissingTypeHintError');
|
|
450
|
+
expect(err.code).toBe('FUNC_MISSING_TYPE_HINT');
|
|
451
|
+
expect(err.cause).toBe(cause);
|
|
452
|
+
expect(err.traceId).toBe(traceId);
|
|
453
|
+
expect(err.message).toContain('myParam');
|
|
454
|
+
expect(err.message).toContain('myFunc');
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('FuncMissingTypeHintError without options', () => {
|
|
458
|
+
const err = new FuncMissingTypeHintError('myFunc', 'myParam');
|
|
459
|
+
expect(err.cause).toBeUndefined();
|
|
460
|
+
expect(err.traceId).toBeUndefined();
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it('FuncMissingReturnTypeError with cause and traceId', () => {
|
|
464
|
+
const err = new FuncMissingReturnTypeError('myFunc', { cause, traceId });
|
|
465
|
+
expect(err.name).toBe('FuncMissingReturnTypeError');
|
|
466
|
+
expect(err.code).toBe('FUNC_MISSING_RETURN_TYPE');
|
|
467
|
+
expect(err.cause).toBe(cause);
|
|
468
|
+
expect(err.traceId).toBe(traceId);
|
|
469
|
+
expect(err.message).toContain('myFunc');
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('FuncMissingReturnTypeError without options', () => {
|
|
473
|
+
const err = new FuncMissingReturnTypeError('myFunc');
|
|
474
|
+
expect(err.cause).toBeUndefined();
|
|
475
|
+
expect(err.traceId).toBeUndefined();
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('BindingInvalidTargetError with cause and traceId', () => {
|
|
479
|
+
const err = new BindingInvalidTargetError('bad:target', { cause, traceId });
|
|
480
|
+
expect(err.cause).toBe(cause);
|
|
481
|
+
expect(err.traceId).toBe(traceId);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('BindingInvalidTargetError without options', () => {
|
|
485
|
+
const err = new BindingInvalidTargetError('bad:target');
|
|
486
|
+
expect(err.cause).toBeUndefined();
|
|
487
|
+
expect(err.traceId).toBeUndefined();
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it('BindingModuleNotFoundError with cause and traceId', () => {
|
|
491
|
+
const err = new BindingModuleNotFoundError('some.module', { cause, traceId });
|
|
492
|
+
expect(err.cause).toBe(cause);
|
|
493
|
+
expect(err.traceId).toBe(traceId);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('BindingModuleNotFoundError without options', () => {
|
|
497
|
+
const err = new BindingModuleNotFoundError('some.module');
|
|
498
|
+
expect(err.cause).toBeUndefined();
|
|
499
|
+
expect(err.traceId).toBeUndefined();
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('BindingCallableNotFoundError with cause and traceId', () => {
|
|
503
|
+
const err = new BindingCallableNotFoundError('fn', 'some.module', { cause, traceId });
|
|
504
|
+
expect(err.cause).toBe(cause);
|
|
505
|
+
expect(err.traceId).toBe(traceId);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('BindingCallableNotFoundError without options', () => {
|
|
509
|
+
const err = new BindingCallableNotFoundError('fn', 'some.module');
|
|
510
|
+
expect(err.cause).toBeUndefined();
|
|
511
|
+
expect(err.traceId).toBeUndefined();
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('BindingNotCallableError with cause and traceId', () => {
|
|
515
|
+
const err = new BindingNotCallableError('some:target', { cause, traceId });
|
|
516
|
+
expect(err.cause).toBe(cause);
|
|
517
|
+
expect(err.traceId).toBe(traceId);
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it('BindingNotCallableError without options', () => {
|
|
521
|
+
const err = new BindingNotCallableError('some:target');
|
|
522
|
+
expect(err.cause).toBeUndefined();
|
|
523
|
+
expect(err.traceId).toBeUndefined();
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it('BindingSchemaMissingError with cause and traceId', () => {
|
|
527
|
+
const err = new BindingSchemaMissingError('some:target', { cause, traceId });
|
|
528
|
+
expect(err.cause).toBe(cause);
|
|
529
|
+
expect(err.traceId).toBe(traceId);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
it('BindingSchemaMissingError without options', () => {
|
|
533
|
+
const err = new BindingSchemaMissingError('some:target');
|
|
534
|
+
expect(err.cause).toBeUndefined();
|
|
535
|
+
expect(err.traceId).toBeUndefined();
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it('BindingFileInvalidError with cause and traceId', () => {
|
|
539
|
+
const err = new BindingFileInvalidError('/file.yaml', 'parse error', { cause, traceId });
|
|
540
|
+
expect(err.cause).toBe(cause);
|
|
541
|
+
expect(err.traceId).toBe(traceId);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it('BindingFileInvalidError without options', () => {
|
|
545
|
+
const err = new BindingFileInvalidError('/file.yaml', 'parse error');
|
|
546
|
+
expect(err.cause).toBeUndefined();
|
|
547
|
+
expect(err.traceId).toBeUndefined();
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it('CircularDependencyError with cause and traceId', () => {
|
|
551
|
+
const err = new CircularDependencyError(['a', 'b', 'a'], { cause, traceId });
|
|
552
|
+
expect(err.cause).toBe(cause);
|
|
553
|
+
expect(err.traceId).toBe(traceId);
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it('CircularDependencyError without options', () => {
|
|
557
|
+
const err = new CircularDependencyError(['a', 'b', 'a']);
|
|
558
|
+
expect(err.cause).toBeUndefined();
|
|
559
|
+
expect(err.traceId).toBeUndefined();
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it('ModuleLoadError with cause and traceId', () => {
|
|
563
|
+
const err = new ModuleLoadError('mod.a', 'file not found', { cause, traceId });
|
|
564
|
+
expect(err.cause).toBe(cause);
|
|
565
|
+
expect(err.traceId).toBe(traceId);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it('ModuleLoadError without options', () => {
|
|
569
|
+
const err = new ModuleLoadError('mod.a', 'file not found');
|
|
570
|
+
expect(err.cause).toBeUndefined();
|
|
571
|
+
expect(err.traceId).toBeUndefined();
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('ModuleExecuteError with cause and traceId', () => {
|
|
575
|
+
const err = new ModuleExecuteError('mod.a', 'runtime error', { cause, traceId });
|
|
576
|
+
expect(err.name).toBe('ModuleExecuteError');
|
|
577
|
+
expect(err.code).toBe('MODULE_EXECUTE_ERROR');
|
|
578
|
+
expect(err.cause).toBe(cause);
|
|
579
|
+
expect(err.traceId).toBe(traceId);
|
|
580
|
+
expect(err.message).toContain('mod.a');
|
|
581
|
+
expect(err.message).toContain('runtime error');
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('ModuleExecuteError without options', () => {
|
|
585
|
+
const err = new ModuleExecuteError('mod.a', 'runtime error');
|
|
586
|
+
expect(err.cause).toBeUndefined();
|
|
587
|
+
expect(err.traceId).toBeUndefined();
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it('InternalError with cause and traceId', () => {
|
|
591
|
+
const err = new InternalError('something broke', { cause, traceId });
|
|
592
|
+
expect(err.name).toBe('InternalError');
|
|
593
|
+
expect(err.code).toBe('GENERAL_INTERNAL_ERROR');
|
|
594
|
+
expect(err.cause).toBe(cause);
|
|
595
|
+
expect(err.traceId).toBe(traceId);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
it('InternalError without options', () => {
|
|
599
|
+
const err = new InternalError('something broke');
|
|
600
|
+
expect(err.cause).toBeUndefined();
|
|
601
|
+
expect(err.traceId).toBeUndefined();
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
it('InternalError uses default message when no arguments provided', () => {
|
|
605
|
+
const err = new InternalError();
|
|
606
|
+
expect(err.message).toBe('Internal error');
|
|
607
|
+
});
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
describe('ErrorCodes', () => {
|
|
611
|
+
it('contains MIDDLEWARE_CHAIN_ERROR', () => {
|
|
612
|
+
expect(ErrorCodes.MIDDLEWARE_CHAIN_ERROR).toBe('MIDDLEWARE_CHAIN_ERROR');
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
it('contains all expected error codes', () => {
|
|
616
|
+
expect(ErrorCodes.CONFIG_NOT_FOUND).toBe('CONFIG_NOT_FOUND');
|
|
617
|
+
expect(ErrorCodes.CONFIG_INVALID).toBe('CONFIG_INVALID');
|
|
618
|
+
expect(ErrorCodes.ACL_RULE_ERROR).toBe('ACL_RULE_ERROR');
|
|
619
|
+
expect(ErrorCodes.ACL_DENIED).toBe('ACL_DENIED');
|
|
620
|
+
expect(ErrorCodes.MODULE_NOT_FOUND).toBe('MODULE_NOT_FOUND');
|
|
621
|
+
expect(ErrorCodes.MODULE_TIMEOUT).toBe('MODULE_TIMEOUT');
|
|
622
|
+
expect(ErrorCodes.MODULE_LOAD_ERROR).toBe('MODULE_LOAD_ERROR');
|
|
623
|
+
expect(ErrorCodes.MODULE_EXECUTE_ERROR).toBe('MODULE_EXECUTE_ERROR');
|
|
624
|
+
expect(ErrorCodes.SCHEMA_VALIDATION_ERROR).toBe('SCHEMA_VALIDATION_ERROR');
|
|
625
|
+
expect(ErrorCodes.SCHEMA_NOT_FOUND).toBe('SCHEMA_NOT_FOUND');
|
|
626
|
+
expect(ErrorCodes.SCHEMA_PARSE_ERROR).toBe('SCHEMA_PARSE_ERROR');
|
|
627
|
+
expect(ErrorCodes.SCHEMA_CIRCULAR_REF).toBe('SCHEMA_CIRCULAR_REF');
|
|
628
|
+
expect(ErrorCodes.CALL_DEPTH_EXCEEDED).toBe('CALL_DEPTH_EXCEEDED');
|
|
629
|
+
expect(ErrorCodes.CIRCULAR_CALL).toBe('CIRCULAR_CALL');
|
|
630
|
+
expect(ErrorCodes.CALL_FREQUENCY_EXCEEDED).toBe('CALL_FREQUENCY_EXCEEDED');
|
|
631
|
+
expect(ErrorCodes.GENERAL_INVALID_INPUT).toBe('GENERAL_INVALID_INPUT');
|
|
632
|
+
expect(ErrorCodes.GENERAL_INTERNAL_ERROR).toBe('GENERAL_INTERNAL_ERROR');
|
|
633
|
+
expect(ErrorCodes.FUNC_MISSING_TYPE_HINT).toBe('FUNC_MISSING_TYPE_HINT');
|
|
634
|
+
expect(ErrorCodes.FUNC_MISSING_RETURN_TYPE).toBe('FUNC_MISSING_RETURN_TYPE');
|
|
635
|
+
expect(ErrorCodes.BINDING_INVALID_TARGET).toBe('BINDING_INVALID_TARGET');
|
|
636
|
+
expect(ErrorCodes.BINDING_MODULE_NOT_FOUND).toBe('BINDING_MODULE_NOT_FOUND');
|
|
637
|
+
expect(ErrorCodes.BINDING_CALLABLE_NOT_FOUND).toBe('BINDING_CALLABLE_NOT_FOUND');
|
|
638
|
+
expect(ErrorCodes.BINDING_NOT_CALLABLE).toBe('BINDING_NOT_CALLABLE');
|
|
639
|
+
expect(ErrorCodes.BINDING_SCHEMA_MISSING).toBe('BINDING_SCHEMA_MISSING');
|
|
640
|
+
expect(ErrorCodes.BINDING_FILE_INVALID).toBe('BINDING_FILE_INVALID');
|
|
641
|
+
expect(ErrorCodes.CIRCULAR_DEPENDENCY).toBe('CIRCULAR_DEPENDENCY');
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it('is frozen and cannot be mutated', () => {
|
|
645
|
+
expect(Object.isFrozen(ErrorCodes)).toBe(true);
|
|
646
|
+
});
|
|
647
|
+
});
|