@hg-ts/exception 0.0.15
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/.eslintcache +1 -0
- package/.eslintrc.json +1 -0
- package/.mocharc.cjs +1 -0
- package/README.md +1 -0
- package/dist/consts.d.ts +2 -0
- package/dist/consts.d.ts.map +1 -0
- package/dist/consts.js +5 -0
- package/dist/consts.js.map +1 -0
- package/dist/exceptions/aggregate-error.exception.d.ts +5 -0
- package/dist/exceptions/aggregate-error.exception.d.ts.map +1 -0
- package/dist/exceptions/aggregate-error.exception.js +24 -0
- package/dist/exceptions/aggregate-error.exception.js.map +1 -0
- package/dist/exceptions/base.aggregate.exception.d.ts +13 -0
- package/dist/exceptions/base.aggregate.exception.d.ts.map +1 -0
- package/dist/exceptions/base.aggregate.exception.js +33 -0
- package/dist/exceptions/base.aggregate.exception.js.map +1 -0
- package/dist/exceptions/base.exception.d.ts +36 -0
- package/dist/exceptions/base.exception.d.ts.map +1 -0
- package/dist/exceptions/base.exception.js +96 -0
- package/dist/exceptions/base.exception.js.map +1 -0
- package/dist/exceptions/error.exception.d.ts +5 -0
- package/dist/exceptions/error.exception.d.ts.map +1 -0
- package/dist/exceptions/error.exception.js +17 -0
- package/dist/exceptions/error.exception.js.map +1 -0
- package/dist/exceptions/forbidden.exception.d.ts +4 -0
- package/dist/exceptions/forbidden.exception.d.ts.map +1 -0
- package/dist/exceptions/forbidden.exception.js +8 -0
- package/dist/exceptions/forbidden.exception.js.map +1 -0
- package/dist/exceptions/index.d.ts +9 -0
- package/dist/exceptions/index.d.ts.map +1 -0
- package/dist/exceptions/index.js +12 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/not-implemented.exception.d.ts +5 -0
- package/dist/exceptions/not-implemented.exception.d.ts.map +1 -0
- package/dist/exceptions/not-implemented.exception.js +11 -0
- package/dist/exceptions/not-implemented.exception.js.map +1 -0
- package/dist/exceptions/unknown.exception.d.ts +5 -0
- package/dist/exceptions/unknown.exception.d.ts.map +1 -0
- package/dist/exceptions/unknown.exception.js +11 -0
- package/dist/exceptions/unknown.exception.js.map +1 -0
- package/dist/exceptions/will-never-happened.exception.d.ts +5 -0
- package/dist/exceptions/will-never-happened.exception.d.ts.map +1 -0
- package/dist/exceptions/will-never-happened.exception.js +11 -0
- package/dist/exceptions/will-never-happened.exception.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/serialization.test-suite.d.ts +13 -0
- package/dist/tests/serialization.test-suite.d.ts.map +1 -0
- package/dist/tests/serialization.test-suite.js +142 -0
- package/dist/tests/serialization.test-suite.js.map +1 -0
- package/dist/tests/test.aggregate-exception.d.ts +5 -0
- package/dist/tests/test.aggregate-exception.d.ts.map +1 -0
- package/dist/tests/test.aggregate-exception.js +16 -0
- package/dist/tests/test.aggregate-exception.js.map +1 -0
- package/dist/tests/test.d.ts +6 -0
- package/dist/tests/test.d.ts.map +1 -0
- package/dist/tests/test.exception.d.ts +5 -0
- package/dist/tests/test.exception.d.ts.map +1 -0
- package/dist/tests/test.exception.js +11 -0
- package/dist/tests/test.exception.js.map +1 -0
- package/dist/tests/test.js +22 -0
- package/dist/tests/test.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/stack-trace.formatter.d.ts +6 -0
- package/dist/utils/stack-trace.formatter.d.ts.map +1 -0
- package/dist/utils/stack-trace.formatter.js +30 -0
- package/dist/utils/stack-trace.formatter.js.map +1 -0
- package/dist-esm/consts.d.ts +2 -0
- package/dist-esm/consts.d.ts.map +1 -0
- package/dist-esm/consts.js +2 -0
- package/dist-esm/consts.js.map +1 -0
- package/dist-esm/exceptions/aggregate-error.exception.d.ts +5 -0
- package/dist-esm/exceptions/aggregate-error.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/aggregate-error.exception.js +20 -0
- package/dist-esm/exceptions/aggregate-error.exception.js.map +1 -0
- package/dist-esm/exceptions/base.aggregate.exception.d.ts +13 -0
- package/dist-esm/exceptions/base.aggregate.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/base.aggregate.exception.js +29 -0
- package/dist-esm/exceptions/base.aggregate.exception.js.map +1 -0
- package/dist-esm/exceptions/base.exception.d.ts +36 -0
- package/dist-esm/exceptions/base.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/base.exception.js +91 -0
- package/dist-esm/exceptions/base.exception.js.map +1 -0
- package/dist-esm/exceptions/error.exception.d.ts +5 -0
- package/dist-esm/exceptions/error.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/error.exception.js +13 -0
- package/dist-esm/exceptions/error.exception.js.map +1 -0
- package/dist-esm/exceptions/forbidden.exception.d.ts +4 -0
- package/dist-esm/exceptions/forbidden.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/forbidden.exception.js +4 -0
- package/dist-esm/exceptions/forbidden.exception.js.map +1 -0
- package/dist-esm/exceptions/index.d.ts +9 -0
- package/dist-esm/exceptions/index.d.ts.map +1 -0
- package/dist-esm/exceptions/index.js +9 -0
- package/dist-esm/exceptions/index.js.map +1 -0
- package/dist-esm/exceptions/not-implemented.exception.d.ts +5 -0
- package/dist-esm/exceptions/not-implemented.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/not-implemented.exception.js +7 -0
- package/dist-esm/exceptions/not-implemented.exception.js.map +1 -0
- package/dist-esm/exceptions/unknown.exception.d.ts +5 -0
- package/dist-esm/exceptions/unknown.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/unknown.exception.js +7 -0
- package/dist-esm/exceptions/unknown.exception.js.map +1 -0
- package/dist-esm/exceptions/will-never-happened.exception.d.ts +5 -0
- package/dist-esm/exceptions/will-never-happened.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/will-never-happened.exception.js +7 -0
- package/dist-esm/exceptions/will-never-happened.exception.js.map +1 -0
- package/dist-esm/index.d.ts +3 -0
- package/dist-esm/index.d.ts.map +1 -0
- package/dist-esm/index.js +3 -0
- package/dist-esm/index.js.map +1 -0
- package/dist-esm/tests/serialization.test-suite.d.ts +13 -0
- package/dist-esm/tests/serialization.test-suite.d.ts.map +1 -0
- package/dist-esm/tests/serialization.test-suite.js +139 -0
- package/dist-esm/tests/serialization.test-suite.js.map +1 -0
- package/dist-esm/tests/test.aggregate-exception.d.ts +5 -0
- package/dist-esm/tests/test.aggregate-exception.d.ts.map +1 -0
- package/dist-esm/tests/test.aggregate-exception.js +12 -0
- package/dist-esm/tests/test.aggregate-exception.js.map +1 -0
- package/dist-esm/tests/test.exception.d.ts +5 -0
- package/dist-esm/tests/test.exception.d.ts.map +1 -0
- package/dist-esm/tests/test.exception.js +7 -0
- package/dist-esm/tests/test.exception.js.map +1 -0
- package/dist-esm/utils/index.d.ts +2 -0
- package/dist-esm/utils/index.d.ts.map +1 -0
- package/dist-esm/utils/index.js +2 -0
- package/dist-esm/utils/index.js.map +1 -0
- package/dist-esm/utils/stack-trace.formatter.d.ts +6 -0
- package/dist-esm/utils/stack-trace.formatter.d.ts.map +1 -0
- package/dist-esm/utils/stack-trace.formatter.js +25 -0
- package/dist-esm/utils/stack-trace.formatter.js.map +1 -0
- package/package.json +37 -0
- package/src/consts.ts +1 -0
- package/src/exceptions/aggregate-error.exception.ts +26 -0
- package/src/exceptions/base.aggregate.exception.ts +51 -0
- package/src/exceptions/base.exception.ts +138 -0
- package/src/exceptions/error.exception.ts +16 -0
- package/src/exceptions/forbidden.exception.ts +3 -0
- package/src/exceptions/index.ts +11 -0
- package/src/exceptions/not-implemented.exception.ts +7 -0
- package/src/exceptions/unknown.exception.ts +7 -0
- package/src/exceptions/will-never-happened.exception.ts +7 -0
- package/src/index.ts +2 -0
- package/src/tests/serialization.test-suite.ts +121 -0
- package/src/tests/test.aggregate-exception.ts +16 -0
- package/src/tests/test.exception.ts +7 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/stack-trace.formatter.ts +30 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './error.exception';
|
|
2
|
+
export * from './aggregate-error.exception';
|
|
3
|
+
export * from './base.exception';
|
|
4
|
+
export * from './base.aggregate.exception';
|
|
5
|
+
export * from './unknown.exception';
|
|
6
|
+
export * from './not-implemented.exception';
|
|
7
|
+
export * from './will-never-happened.exception';
|
|
8
|
+
export * from './forbidden.exception';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAE5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-implemented.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/not-implemented.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,uBAAwB,SAAQ,aAAa;;CAIzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-implemented.exception.js","sourceRoot":"","sources":["../../src/exceptions/not-implemented.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,uBAAwB,SAAQ,aAAa;IACzD;QACC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC1B,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknown.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/unknown.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,gBAAiB,SAAQ,aAAa;gBAC/B,OAAO,EAAE,MAAM;CAGlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknown.exception.js","sourceRoot":"","sources":["../../src/exceptions/unknown.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IAClD,YAAmB,OAAe;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"will-never-happened.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/will-never-happened.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,0BAA2B,SAAQ,aAAa;gBACzC,OAAO,EAAE,MAAM;CAGlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"will-never-happened.exception.js","sourceRoot":"","sources":["../../src/exceptions/will-never-happened.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,0BAA2B,SAAQ,aAAa;IAC5D,YAAmB,OAAe;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '@hg-ts/types';
|
|
2
|
+
import { TestSuite } from '@hg-ts/tests';
|
|
3
|
+
export declare class SerializationTestSuite extends TestSuite {
|
|
4
|
+
commonTest(): Promise<void>;
|
|
5
|
+
baseExceptionFromError(): Promise<void>;
|
|
6
|
+
aggregateExceptionTest(): Promise<void>;
|
|
7
|
+
syncStackTest(): Promise<void>;
|
|
8
|
+
isFromNextTickTest(): Promise<void>;
|
|
9
|
+
isFromImmediateTest(): Promise<void>;
|
|
10
|
+
fromTimeoutTest(): Promise<void>;
|
|
11
|
+
fromIntervalTest(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=serialization.test-suite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.test-suite.d.ts","sourceRoot":"","sources":["../../src/tests/serialization.test-suite.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,OAAO,EAEN,SAAS,EAGT,MAAM,cAAc,CAAC;AAStB,qBACa,sBAAuB,SAAQ,SAAS;IAEvC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAe3B,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAevC,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBvC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAYnC,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAYpC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAYhC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CAY9C"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import '@hg-ts/types';
|
|
3
|
+
import { Test, TestSuite, Describe, expect, } from '@hg-ts/tests';
|
|
4
|
+
import { BaseAggregateException, BaseException, ErrorException, } from '../exceptions';
|
|
5
|
+
import { TestAggregateException } from './test.aggregate-exception';
|
|
6
|
+
import { TestException } from './test.exception';
|
|
7
|
+
let SerializationTestSuite = class SerializationTestSuite extends TestSuite {
|
|
8
|
+
async commonTest() {
|
|
9
|
+
const message = 'Test message';
|
|
10
|
+
const exception = new TestException(message);
|
|
11
|
+
expect(exception).toBeInstanceOf(Error);
|
|
12
|
+
expect(exception).toBeInstanceOf(BaseException);
|
|
13
|
+
expect(exception).toBeInstanceOf(TestException);
|
|
14
|
+
expect(exception.message).toEqual(message);
|
|
15
|
+
expect(exception.code).toBeNull();
|
|
16
|
+
expect(exception.toJSON().name).toEqual(TestException.name);
|
|
17
|
+
expect(exception.toJSON().stack).toBeInstanceOf(Array);
|
|
18
|
+
expect(exception.toJSON().stack).not.toEqual([]);
|
|
19
|
+
}
|
|
20
|
+
async baseExceptionFromError() {
|
|
21
|
+
const message = 'Test message';
|
|
22
|
+
const error = new Error(message);
|
|
23
|
+
const exception = BaseException.fromError(error);
|
|
24
|
+
expect(exception).toBeInstanceOf(Error);
|
|
25
|
+
expect(exception).toBeInstanceOf(BaseException);
|
|
26
|
+
expect(exception).toBeInstanceOf(ErrorException);
|
|
27
|
+
expect(exception.message).toEqual(message);
|
|
28
|
+
expect(exception.code).toBeNull();
|
|
29
|
+
expect(exception.toJSON().stack).toBeInstanceOf(Array);
|
|
30
|
+
expect(exception.toJSON().stack).not.toEqual([]);
|
|
31
|
+
}
|
|
32
|
+
async aggregateExceptionTest() {
|
|
33
|
+
const message = 'Test aggregate message';
|
|
34
|
+
const exception = new TestAggregateException(message);
|
|
35
|
+
expect(exception).toBeInstanceOf(Error);
|
|
36
|
+
expect(exception).toBeInstanceOf(BaseException);
|
|
37
|
+
expect(exception).toBeInstanceOf(BaseAggregateException);
|
|
38
|
+
expect(exception).toBeInstanceOf(TestAggregateException);
|
|
39
|
+
expect(exception.message).toEqual(message);
|
|
40
|
+
expect(exception.code).toBeNull();
|
|
41
|
+
expect(exception.exceptions).toBeInstanceOf(Array);
|
|
42
|
+
expect(exception.exceptions).toHaveLength(3);
|
|
43
|
+
}
|
|
44
|
+
async syncStackTest() {
|
|
45
|
+
const { stack } = new TestException('Test message').toJSON();
|
|
46
|
+
expect(stack[0].startsWith('at SerializationTestSuite.syncStackTest')).toBeTruthy();
|
|
47
|
+
}
|
|
48
|
+
async isFromNextTickTest() {
|
|
49
|
+
return new Promise(resolve => {
|
|
50
|
+
process.nextTick(() => {
|
|
51
|
+
const exception = new TestException('Test message');
|
|
52
|
+
expect(exception.isFromNextTick()).toBeTruthy();
|
|
53
|
+
resolve();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async isFromImmediateTest() {
|
|
58
|
+
return new Promise(resolve => {
|
|
59
|
+
setImmediate(() => {
|
|
60
|
+
const exception = new TestException('Test message');
|
|
61
|
+
expect(exception.isFromImmediate()).toBeTruthy();
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async fromTimeoutTest() {
|
|
67
|
+
return new Promise(resolve => {
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
const exception = new TestException('Test message');
|
|
70
|
+
expect(exception.isFromTimer()).toBeTruthy();
|
|
71
|
+
resolve();
|
|
72
|
+
}, 0);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async fromIntervalTest() {
|
|
76
|
+
let interval;
|
|
77
|
+
return new Promise(resolve => {
|
|
78
|
+
interval = setInterval(() => {
|
|
79
|
+
const exception = new TestException('Test message');
|
|
80
|
+
expect(exception.isFromTimer()).toBeTruthy();
|
|
81
|
+
clearInterval(interval);
|
|
82
|
+
resolve();
|
|
83
|
+
}, 0);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
__decorate([
|
|
88
|
+
Test(),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", []),
|
|
91
|
+
__metadata("design:returntype", Promise)
|
|
92
|
+
], SerializationTestSuite.prototype, "commonTest", null);
|
|
93
|
+
__decorate([
|
|
94
|
+
Test(),
|
|
95
|
+
__metadata("design:type", Function),
|
|
96
|
+
__metadata("design:paramtypes", []),
|
|
97
|
+
__metadata("design:returntype", Promise)
|
|
98
|
+
], SerializationTestSuite.prototype, "baseExceptionFromError", null);
|
|
99
|
+
__decorate([
|
|
100
|
+
Test(),
|
|
101
|
+
__metadata("design:type", Function),
|
|
102
|
+
__metadata("design:paramtypes", []),
|
|
103
|
+
__metadata("design:returntype", Promise)
|
|
104
|
+
], SerializationTestSuite.prototype, "aggregateExceptionTest", null);
|
|
105
|
+
__decorate([
|
|
106
|
+
Test(),
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", []),
|
|
109
|
+
__metadata("design:returntype", Promise)
|
|
110
|
+
], SerializationTestSuite.prototype, "syncStackTest", null);
|
|
111
|
+
__decorate([
|
|
112
|
+
Test(),
|
|
113
|
+
__metadata("design:type", Function),
|
|
114
|
+
__metadata("design:paramtypes", []),
|
|
115
|
+
__metadata("design:returntype", Promise)
|
|
116
|
+
], SerializationTestSuite.prototype, "isFromNextTickTest", null);
|
|
117
|
+
__decorate([
|
|
118
|
+
Test(),
|
|
119
|
+
__metadata("design:type", Function),
|
|
120
|
+
__metadata("design:paramtypes", []),
|
|
121
|
+
__metadata("design:returntype", Promise)
|
|
122
|
+
], SerializationTestSuite.prototype, "isFromImmediateTest", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
Test(),
|
|
125
|
+
__metadata("design:type", Function),
|
|
126
|
+
__metadata("design:paramtypes", []),
|
|
127
|
+
__metadata("design:returntype", Promise)
|
|
128
|
+
], SerializationTestSuite.prototype, "fromTimeoutTest", null);
|
|
129
|
+
__decorate([
|
|
130
|
+
Test(),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", []),
|
|
133
|
+
__metadata("design:returntype", Promise)
|
|
134
|
+
], SerializationTestSuite.prototype, "fromIntervalTest", null);
|
|
135
|
+
SerializationTestSuite = __decorate([
|
|
136
|
+
Describe()
|
|
137
|
+
], SerializationTestSuite);
|
|
138
|
+
export { SerializationTestSuite };
|
|
139
|
+
//# sourceMappingURL=serialization.test-suite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.test-suite.js","sourceRoot":"","sources":["../../src/tests/serialization.test-suite.ts"],"names":[],"mappings":";AAAA,OAAO,cAAc,CAAC;AACtB,OAAO,EACN,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,MAAM,GACN,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,sBAAsB,EACtB,aAAa,EACb,cAAc,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,SAAS;IAE7C,KAAK,CAAC,UAAU;QACtB,MAAM,OAAO,GAAG,cAAc,CAAC;QAC/B,MAAM,SAAS,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QAE7C,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAChD,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAChD,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3C,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QAClC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.aggregate-exception.d.ts","sourceRoot":"","sources":["../../src/tests/test.aggregate-exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGvD,qBAAa,sBAAuB,SAAQ,sBAAsB;gBAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAWjD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseAggregateException } from '../exceptions';
|
|
2
|
+
import { TestException } from './test.exception';
|
|
3
|
+
export class TestAggregateException extends BaseAggregateException {
|
|
4
|
+
constructor(message, code) {
|
|
5
|
+
super([
|
|
6
|
+
new TestException('First inner exception'),
|
|
7
|
+
new TestException('Second inner exception'),
|
|
8
|
+
new TestException('Third inner exception'),
|
|
9
|
+
], message, { code });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=test.aggregate-exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.aggregate-exception.js","sourceRoot":"","sources":["../../src/tests/test.aggregate-exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IACjE,YAAmB,OAAe,EAAE,IAAa;QAChD,KAAK,CACJ;YACC,IAAI,aAAa,CAAC,uBAAuB,CAAC;YAC1C,IAAI,aAAa,CAAC,wBAAwB,CAAC;YAC3C,IAAI,aAAa,CAAC,uBAAuB,CAAC;SAC1C,EACD,OAAO,EACP,EAAE,IAAI,EAAE,CACR,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.exception.d.ts","sourceRoot":"","sources":["../../src/tests/test.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,qBAAa,aAAc,SAAQ,aAAa;gBAC5B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAGjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.exception.js","sourceRoot":"","sources":["../../src/tests/test.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC/C,YAAmB,OAAe,EAAE,IAAa;QAChD,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1B,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class StackTraceFormatter {
|
|
2
|
+
static format(stack: string, exceptionName: string): string[];
|
|
3
|
+
protected static getStackLines(stack: string, exceptionName: string): string[];
|
|
4
|
+
protected static isInternalStackLine(line: string): boolean;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=stack-trace.formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack-trace.formatter.d.ts","sourceRoot":"","sources":["../../src/utils/stack-trace.formatter.ts"],"names":[],"mappings":"AAGA,qBAAa,mBAAmB;WACjB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE;IAIpE,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE;IAkB9E,SAAS,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAG3D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import { SOURCE_MAP_ENABLED } from '../consts';
|
|
3
|
+
export class StackTraceFormatter {
|
|
4
|
+
static format(stack, exceptionName) {
|
|
5
|
+
return StackTraceFormatter.getStackLines(stack, exceptionName);
|
|
6
|
+
}
|
|
7
|
+
static getStackLines(stack, exceptionName) {
|
|
8
|
+
let lines = stack.split(os.EOL)
|
|
9
|
+
.splice(1)
|
|
10
|
+
.filter(stackLine => !StackTraceFormatter.isInternalStackLine(stackLine))
|
|
11
|
+
.map(line => line.trim());
|
|
12
|
+
if (SOURCE_MAP_ENABLED) {
|
|
13
|
+
lines = lines.slice(4);
|
|
14
|
+
}
|
|
15
|
+
const lineFromExceptionConstructor = lines.findIndex(line => line.startsWith(`at new ${exceptionName}`));
|
|
16
|
+
if (lineFromExceptionConstructor > -1) {
|
|
17
|
+
return lines.slice(lineFromExceptionConstructor + 1);
|
|
18
|
+
}
|
|
19
|
+
return lines;
|
|
20
|
+
}
|
|
21
|
+
static isInternalStackLine(line) {
|
|
22
|
+
return line.includes('internal/') && !line.includes('processTicksAndRejections');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=stack-trace.formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack-trace.formatter.js","sourceRoot":"","sources":["../../src/utils/stack-trace.formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,OAAO,mBAAmB;IACxB,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,aAAqB;QACxD,OAAO,mBAAmB,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,CAAC;IAES,MAAM,CAAC,aAAa,CAAC,KAAa,EAAE,aAAqB;QAClE,IAAI,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC;aAC7B,MAAM,CAAC,CAAC,CAAC;aACT,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;aACxE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAE3B,IAAI,kBAAkB,EAAE;YACvB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACvB;QACD,MAAM,4BAA4B,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,aAAa,EAAE,CAAC,CAAC,CAAC;QAEzG,IAAI,4BAA4B,GAAG,CAAC,CAAC,EAAE;YACtC,OAAO,KAAK,CAAC,KAAK,CAAC,4BAA4B,GAAG,CAAC,CAAC,CAAC;SACrD;QAED,OAAO,KAAK,CAAC;IACd,CAAC;IAES,MAAM,CAAC,mBAAmB,CAAC,IAAY;QAChD,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC;IAClF,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hg-ts/exception",
|
|
3
|
+
"version": "0.0.15",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist-esm/index.js",
|
|
6
|
+
"repository": "git@gitlab.com:hyper-graph/framework.git",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prepack": "yarn build && yarn lint && yarn test",
|
|
9
|
+
"build": "hg build",
|
|
10
|
+
"build:dev": "hg build:dev",
|
|
11
|
+
"lint": "hg lint",
|
|
12
|
+
"lint:fix": "hg lint:fix",
|
|
13
|
+
"test": "hg test"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@hg-ts-config/eslint-config": "0.0.15",
|
|
17
|
+
"@hg-ts-config/typescript": "0.0.15",
|
|
18
|
+
"@hg-ts/cli": "0.0.15",
|
|
19
|
+
"@hg-ts/tests": "0.0.15",
|
|
20
|
+
"@hg-ts/types": "0.0.15",
|
|
21
|
+
"@types/node": "18.0.3",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "5.33.1",
|
|
23
|
+
"@typescript-eslint/parser": "5.33.1",
|
|
24
|
+
"eslint": "8.24.0",
|
|
25
|
+
"eslint-formatter-codeframe": "7.32.1",
|
|
26
|
+
"mocha": "10.0.0",
|
|
27
|
+
"mocha-junit-reporter": "2.0.2",
|
|
28
|
+
"reflect-metadata": "0.1.13",
|
|
29
|
+
"tsc-watch": "5.0.3",
|
|
30
|
+
"tslib": "2.4.0",
|
|
31
|
+
"typescript": "4.7.4"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"reflect-metadata": "*",
|
|
35
|
+
"tslib": "*"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/consts.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SOURCE_MAP_ENABLED = !!(new Error().stack?.includes('->'));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseAggregateException } from './base.aggregate.exception';
|
|
2
|
+
import { BaseException } from './base.exception';
|
|
3
|
+
|
|
4
|
+
export class AggregateErrorException extends BaseAggregateException {
|
|
5
|
+
public constructor(error: AggregateError) {
|
|
6
|
+
const { errors } = error;
|
|
7
|
+
|
|
8
|
+
super(
|
|
9
|
+
errors
|
|
10
|
+
.map(error => {
|
|
11
|
+
if (error instanceof AggregateError) {
|
|
12
|
+
BaseAggregateException.fromError(error);
|
|
13
|
+
}
|
|
14
|
+
if (error instanceof Error) {
|
|
15
|
+
return BaseException.fromError(error);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
})
|
|
20
|
+
.filter((exception): exception is BaseException => exception !== null),
|
|
21
|
+
error.message,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
(this as any).stack = error.stack;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AggregateErrorException } from './aggregate-error.exception';
|
|
2
|
+
import {
|
|
3
|
+
BaseException,
|
|
4
|
+
ExceptionOptions,
|
|
5
|
+
JSONBaseException,
|
|
6
|
+
PAD_COUNT_PER_DEPTH,
|
|
7
|
+
} from './base.exception';
|
|
8
|
+
|
|
9
|
+
export type JSONBaseAggregateException = Omit<JSONBaseException, 'cause'> & {
|
|
10
|
+
exceptions: JSONBaseException[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type BaseAggregateExceptionOptions = Omit<ExceptionOptions, 'cause'>;
|
|
14
|
+
|
|
15
|
+
export abstract class BaseAggregateException extends BaseException {
|
|
16
|
+
public readonly exceptions: BaseException[];
|
|
17
|
+
|
|
18
|
+
protected constructor(
|
|
19
|
+
exceptions: BaseException[],
|
|
20
|
+
message: string,
|
|
21
|
+
options?: BaseAggregateExceptionOptions,
|
|
22
|
+
) {
|
|
23
|
+
super(message, options);
|
|
24
|
+
|
|
25
|
+
this.exceptions = exceptions;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public override toJSON(): JSONBaseAggregateException {
|
|
29
|
+
const baseJson = super.toJSON();
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...baseJson,
|
|
33
|
+
exceptions: this.exceptions.map(exception => exception.toJSON()),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static override fromError(error: AggregateError): BaseAggregateException {
|
|
38
|
+
return new AggregateErrorException(error);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected override injectBeforeStack(padCount: number): string[] {
|
|
42
|
+
const innerExceptionsInfo = this.exceptions
|
|
43
|
+
.map(exception => exception['getStringifyFirstLine']())
|
|
44
|
+
.map(line => BaseException.padLine(line, padCount));
|
|
45
|
+
|
|
46
|
+
return [
|
|
47
|
+
BaseException.padLine('Aggregated exceptions info:', padCount - PAD_COUNT_PER_DEPTH),
|
|
48
|
+
...innerExceptionsInfo,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import * as os from 'os';
|
|
2
|
+
import {
|
|
3
|
+
InspectOptionsStylized,
|
|
4
|
+
inspect,
|
|
5
|
+
} from 'util';
|
|
6
|
+
|
|
7
|
+
import { StackTraceFormatter } from '../utils';
|
|
8
|
+
import { ErrorException } from './error.exception';
|
|
9
|
+
|
|
10
|
+
export type JSONBaseException = {
|
|
11
|
+
name: string;
|
|
12
|
+
code: Nullable<number>;
|
|
13
|
+
message: string;
|
|
14
|
+
stack: string[];
|
|
15
|
+
cause?: JSONBaseException;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ExceptionOptions = {
|
|
19
|
+
cause?: BaseException | undefined;
|
|
20
|
+
code?: number | undefined;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const PAD_COUNT_PER_DEPTH = 4;
|
|
24
|
+
|
|
25
|
+
export abstract class BaseException extends Error {
|
|
26
|
+
public readonly code: Nullable<number> = null;
|
|
27
|
+
public override readonly stack: string;
|
|
28
|
+
public override readonly message: string;
|
|
29
|
+
public override readonly cause?: BaseException;
|
|
30
|
+
private serialized: Nullable<JSONBaseException> = null;
|
|
31
|
+
|
|
32
|
+
public constructor(message: string, codeOrOptions: ExceptionOptions = {}) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.message = message;
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if (codeOrOptions.cause) {
|
|
38
|
+
this.cause = codeOrOptions.cause;
|
|
39
|
+
}
|
|
40
|
+
if (codeOrOptions.code) {
|
|
41
|
+
this.code = codeOrOptions.code;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Error.captureStackTrace(this, this.getCtor());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public override get name(): string {
|
|
48
|
+
const { name } = this.getCtor();
|
|
49
|
+
|
|
50
|
+
return name;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public toJSON(): JSONBaseException {
|
|
54
|
+
if (this.serialized === null) {
|
|
55
|
+
const { name, message, stack, code, cause } = this;
|
|
56
|
+
|
|
57
|
+
this.serialized = {
|
|
58
|
+
name,
|
|
59
|
+
code,
|
|
60
|
+
message,
|
|
61
|
+
stack: StackTraceFormatter.format(stack, this.name),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (cause) {
|
|
65
|
+
this.serialized.cause = cause.toJSON();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return this.serialized;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public override toString(padCount = PAD_COUNT_PER_DEPTH): string {
|
|
73
|
+
const { stack } = this.toJSON();
|
|
74
|
+
const formattedStack = stack.map(line => BaseException.padLine(line, padCount));
|
|
75
|
+
|
|
76
|
+
const errorLines = [
|
|
77
|
+
this.getStringifyFirstLine(),
|
|
78
|
+
...this.injectBeforeStack(padCount + PAD_COUNT_PER_DEPTH),
|
|
79
|
+
...formattedStack,
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
return errorLines.join(os.EOL);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public [inspect.custom](_depth: Nullable<number>, { stylize }: InspectOptionsStylized): string {
|
|
86
|
+
return stylize(this.toString(), 'regexp');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public isFromNextTick(): boolean {
|
|
90
|
+
const lastLine = this.getLastStackLine();
|
|
91
|
+
|
|
92
|
+
return lastLine.includes('processTicksAndRejections');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public isFromImmediate(): boolean {
|
|
96
|
+
const lastLine = this.getLastStackLine();
|
|
97
|
+
|
|
98
|
+
return lastLine.includes('Immediate._onImmediate');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public isFromTimer(): boolean {
|
|
102
|
+
const lastLine = this.getLastStackLine();
|
|
103
|
+
|
|
104
|
+
return lastLine.includes('Timeout._onTimeout');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public static fromError(error: Error): BaseException {
|
|
108
|
+
return new ErrorException(error);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected getCtor(): Function {
|
|
112
|
+
return Object.getPrototypeOf(this)!.constructor;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
protected getStringifyFirstLine(): string {
|
|
116
|
+
const { name, code, message } = this.toJSON();
|
|
117
|
+
|
|
118
|
+
return `${name}${code === null ? '' : ` [code: ${code}]`}: ${message}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
protected injectBeforeStack(padCount: number): string[] {
|
|
122
|
+
if (this.cause) {
|
|
123
|
+
return [BaseException.padLine(this.cause.getStringifyFirstLine(), padCount)];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
protected static padLine(line: string, padCount: number): string {
|
|
130
|
+
return `${' '.repeat(padCount)}${line}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private getLastStackLine(): string {
|
|
134
|
+
const { stack } = this.toJSON();
|
|
135
|
+
|
|
136
|
+
return stack[stack.length - 1] ?? '';
|
|
137
|
+
}
|
|
138
|
+
}
|