@posthog/core 1.54.0 → 1.54.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/dist/error-tracking/coercers/error-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/error-coercer.js +11 -3
- package/dist/error-tracking/coercers/error-coercer.mjs +11 -3
- package/dist/error-tracking/error-properties-builder.d.ts +1 -0
- package/dist/error-tracking/error-properties-builder.d.ts.map +1 -1
- package/dist/error-tracking/error-properties-builder.js +130 -34
- package/dist/error-tracking/error-properties-builder.mjs +131 -35
- package/dist/error-tracking/types.d.ts +3 -1
- package/dist/error-tracking/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/error-tracking/coercers/error-coercer.ts +13 -3
- package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +412 -0
- package/src/error-tracking/error-properties-builder.metadata.spec.ts +318 -0
- package/src/error-tracking/error-properties-builder.ts +173 -45
- package/src/error-tracking/types.ts +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-coercer.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/error-coercer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE/E,qBAAa,YAAa,YAAW,oBAAoB,CAAC,KAAK,CAAC;IAC9D,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,KAAK;IAIjC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,eAAe,GAAG,aAAa;
|
|
1
|
+
{"version":3,"file":"error-coercer.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/error-coercer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE/E,qBAAa,YAAa,YAAW,oBAAoB,CAAC,KAAK,CAAC;IAC9D,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,KAAK;IAIjC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,eAAe,GAAG,aAAa;IAiBvD,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,QAAQ;CAYjB"}
|
|
@@ -37,11 +37,12 @@ class ErrorCoercer {
|
|
|
37
37
|
}
|
|
38
38
|
coerce(err, ctx) {
|
|
39
39
|
const stack = this.getStack(err);
|
|
40
|
-
const
|
|
40
|
+
const replacementStack = void 0 === stack ? ctx.syntheticException?.stack : void 0;
|
|
41
|
+
const synthetic = !!replacementStack;
|
|
41
42
|
return {
|
|
42
43
|
type: this.getType(err),
|
|
43
44
|
value: this.getMessage(err, ctx),
|
|
44
|
-
stack: stack ??
|
|
45
|
+
stack: stack ?? replacementStack,
|
|
45
46
|
cause: err.cause ? ctx.next(err.cause) : void 0,
|
|
46
47
|
synthetic
|
|
47
48
|
};
|
|
@@ -55,7 +56,14 @@ class ErrorCoercer {
|
|
|
55
56
|
return String(message);
|
|
56
57
|
}
|
|
57
58
|
getStack(err) {
|
|
58
|
-
|
|
59
|
+
try {
|
|
60
|
+
const stacktrace = err.stacktrace;
|
|
61
|
+
if ('string' == typeof stacktrace && stacktrace.length > 0) return stacktrace;
|
|
62
|
+
const stack = err.stack;
|
|
63
|
+
return 'string' == typeof stack && stack.length > 0 ? stack : void 0;
|
|
64
|
+
} catch {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
69
|
exports.ErrorCoercer = __webpack_exports__.ErrorCoercer;
|
|
@@ -5,11 +5,12 @@ class ErrorCoercer {
|
|
|
5
5
|
}
|
|
6
6
|
coerce(err, ctx) {
|
|
7
7
|
const stack = this.getStack(err);
|
|
8
|
-
const
|
|
8
|
+
const replacementStack = void 0 === stack ? ctx.syntheticException?.stack : void 0;
|
|
9
|
+
const synthetic = !!replacementStack;
|
|
9
10
|
return {
|
|
10
11
|
type: this.getType(err),
|
|
11
12
|
value: this.getMessage(err, ctx),
|
|
12
|
-
stack: stack ??
|
|
13
|
+
stack: stack ?? replacementStack,
|
|
13
14
|
cause: err.cause ? ctx.next(err.cause) : void 0,
|
|
14
15
|
synthetic
|
|
15
16
|
};
|
|
@@ -23,7 +24,14 @@ class ErrorCoercer {
|
|
|
23
24
|
return String(message);
|
|
24
25
|
}
|
|
25
26
|
getStack(err) {
|
|
26
|
-
|
|
27
|
+
try {
|
|
28
|
+
const stacktrace = err.stacktrace;
|
|
29
|
+
if ('string' == typeof stacktrace && stacktrace.length > 0) return stacktrace;
|
|
30
|
+
const stack = err.stack;
|
|
31
|
+
return 'string' == typeof stack && stack.length > 0 ? stack : void 0;
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
export { ErrorCoercer };
|
|
@@ -13,6 +13,7 @@ export declare class ErrorPropertiesBuilder {
|
|
|
13
13
|
private applyModifiers;
|
|
14
14
|
private convertToExceptionList;
|
|
15
15
|
private buildParsingContext;
|
|
16
|
+
private getAggregateErrors;
|
|
16
17
|
buildCoercingContext(mechanism: Mechanism, hint: EventHint, depth?: number): CoercingContext;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=error-properties-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-properties-builder.d.ts","sourceRoot":"","sources":["../../src/error-tracking/error-properties-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EAGf,eAAe,EAEf,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,SAAS,EAGT,SAAS,EAGV,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"error-properties-builder.d.ts","sourceRoot":"","sources":["../../src/error-tracking/error-properties-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EAGf,eAAe,EAEf,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,SAAS,EAGT,SAAS,EAGV,MAAM,SAAS,CAAA;AAiBhB,qBAAa,sBAAsB;IAE/B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,SAAS;gBAFT,QAAQ,EAAE,oBAAoB,CAAC,GAAG,CAAC,EAAE,EACrC,WAAW,EAAE,WAAW,EACxB,SAAS,GAAE,oBAAoB,EAAO;IAGhD,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,SAAc,GAAG,eAAe;IAiBjE,YAAY,CAAC,aAAa,EAAE,eAAe,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IASlH,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;YASP,cAAc;IAQ5B,OAAO,CAAC,sBAAsB;IA2C9B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,kBAAkB;IAoBnB,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,GAAE,MAAU,GAAG,eAAe;CAsGvG"}
|
|
@@ -32,7 +32,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
});
|
|
33
33
|
const index_js_namespaceObject = require("../utils/index.js");
|
|
34
34
|
const external_chunk_ids_js_namespaceObject = require("./chunk-ids.js");
|
|
35
|
-
const
|
|
35
|
+
const MAX_EXCEPTIONS = 50;
|
|
36
|
+
const MAX_AGGREGATE_MEMBER_INSPECTIONS = 1000;
|
|
37
|
+
const MAX_ERROR_PROTOTYPE_DEPTH = 100;
|
|
38
|
+
const MAX_WRAPPER_RECURSION = 4;
|
|
36
39
|
class ErrorPropertiesBuilder {
|
|
37
40
|
constructor(coercers, stackParser, modifiers = []){
|
|
38
41
|
this.coercers = coercers;
|
|
@@ -71,11 +74,14 @@ class ErrorPropertiesBuilder {
|
|
|
71
74
|
let cause;
|
|
72
75
|
if (null != err.cause) cause = this.parseStacktrace(err.cause, ctx);
|
|
73
76
|
let stack;
|
|
74
|
-
if ('' != err.stack && null != err.stack)
|
|
77
|
+
if ('' != err.stack && null != err.stack) try {
|
|
78
|
+
stack = this.applyChunkIds(this.stackParser(err.stack, err.synthetic ? ctx.skipFirstLines : 0), ctx.chunkIdMap);
|
|
79
|
+
} catch {}
|
|
75
80
|
return {
|
|
76
81
|
...err,
|
|
77
82
|
cause,
|
|
78
|
-
stack
|
|
83
|
+
stack,
|
|
84
|
+
errors: err.errors?.map((child)=>this.parseStacktrace(child, ctx))
|
|
79
85
|
};
|
|
80
86
|
}
|
|
81
87
|
applyChunkIds(frames, chunkIdMap) {
|
|
@@ -94,26 +100,39 @@ class ErrorPropertiesBuilder {
|
|
|
94
100
|
return newFrames;
|
|
95
101
|
}
|
|
96
102
|
convertToExceptionList(exceptionWithStack, mechanism) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
type: mechanism.type
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
const exceptionList = [];
|
|
104
|
+
const append = (exception, parentId, source)=>{
|
|
105
|
+
const exceptionId = exceptionList.length;
|
|
106
|
+
const entryMechanism = void 0 === parentId ? {
|
|
107
|
+
type: 'string' == typeof mechanism.type && mechanism.type.length > 0 ? mechanism.type : 'generic',
|
|
108
|
+
...'boolean' == typeof mechanism.handled ? {
|
|
109
|
+
handled: mechanism.handled
|
|
110
|
+
} : void 0 === mechanism.handled ? {
|
|
111
|
+
handled: true
|
|
112
|
+
} : {},
|
|
113
|
+
synthetic: 'boolean' == typeof mechanism.synthetic ? mechanism.synthetic : exception.synthetic,
|
|
114
|
+
exception_id: exceptionId
|
|
115
|
+
} : {
|
|
116
|
+
type: 'chained',
|
|
117
|
+
source,
|
|
118
|
+
synthetic: exception.synthetic,
|
|
119
|
+
exception_id: exceptionId,
|
|
120
|
+
parent_id: parentId
|
|
121
|
+
};
|
|
122
|
+
const currentException = {
|
|
123
|
+
type: exception.type,
|
|
124
|
+
value: exception.value,
|
|
125
|
+
mechanism: entryMechanism
|
|
126
|
+
};
|
|
127
|
+
if (exception.stack) currentException.stacktrace = {
|
|
128
|
+
type: 'raw',
|
|
129
|
+
frames: exception.stack
|
|
130
|
+
};
|
|
131
|
+
exceptionList.push(currentException);
|
|
132
|
+
if (exception.cause) append(exception.cause, exceptionId, 'cause');
|
|
133
|
+
for (const child of exception.errors ?? [])append(child, exceptionId, 'member');
|
|
109
134
|
};
|
|
110
|
-
|
|
111
|
-
currentException
|
|
112
|
-
];
|
|
113
|
-
if (null != exceptionWithStack.cause) exceptionList.push(...this.convertToExceptionList(exceptionWithStack.cause, {
|
|
114
|
-
...mechanism,
|
|
115
|
-
handled: true
|
|
116
|
-
}));
|
|
135
|
+
append(exceptionWithStack);
|
|
117
136
|
return exceptionList;
|
|
118
137
|
}
|
|
119
138
|
buildParsingContext(hint) {
|
|
@@ -123,22 +142,99 @@ class ErrorPropertiesBuilder {
|
|
|
123
142
|
};
|
|
124
143
|
return context;
|
|
125
144
|
}
|
|
145
|
+
getAggregateErrors(input) {
|
|
146
|
+
try {
|
|
147
|
+
if ((0, index_js_namespaceObject.isError)(input)) {
|
|
148
|
+
let prototype = Object.getPrototypeOf(input);
|
|
149
|
+
for(let depth = 0; prototype && depth < MAX_ERROR_PROTOTYPE_DEPTH; depth++){
|
|
150
|
+
const constructor = Object.getOwnPropertyDescriptor(prototype, 'constructor')?.value;
|
|
151
|
+
if ('function' == typeof constructor && 'AggregateError' === constructor.name) {
|
|
152
|
+
const errors = input.errors;
|
|
153
|
+
return (0, index_js_namespaceObject.isArray)(errors) ? errors : void 0;
|
|
154
|
+
}
|
|
155
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch {}
|
|
159
|
+
}
|
|
126
160
|
buildCoercingContext(mechanism, hint, depth = 0) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
161
|
+
let count = 0;
|
|
162
|
+
let memberInspections = 0;
|
|
163
|
+
let hasAggregate = false;
|
|
164
|
+
const seen = new Set();
|
|
165
|
+
const wrappers = [];
|
|
166
|
+
const skipped = {};
|
|
167
|
+
const coerce = (input, depth, wrapperDepth = 0)=>{
|
|
168
|
+
const ctx = createContext(depth, wrapperDepth);
|
|
169
|
+
const forward = ctx.apply;
|
|
170
|
+
ctx.apply = (nextInput)=>{
|
|
171
|
+
wrappers.push(input);
|
|
172
|
+
try {
|
|
173
|
+
return forward(nextInput);
|
|
174
|
+
} finally{
|
|
175
|
+
wrappers.pop();
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
if (wrapperDepth > MAX_WRAPPER_RECURSION || wrapperDepth > 0 && -1 !== wrappers.indexOf(input)) return this.coerceFallback(ctx);
|
|
179
|
+
const isReference = 'object' == typeof input && null !== input || 'function' == typeof input;
|
|
180
|
+
if (0 === wrapperDepth && count >= MAX_EXCEPTIONS || isReference && seen.has(input)) return;
|
|
181
|
+
if (isReference) seen.add(input);
|
|
182
|
+
if (0 === wrapperDepth) count++;
|
|
183
|
+
const errors = this.getAggregateErrors(input);
|
|
184
|
+
hasAggregate ||= !!errors;
|
|
185
|
+
let exception;
|
|
186
|
+
try {
|
|
187
|
+
exception = this.applyCoercers(input, ctx);
|
|
188
|
+
if (!exception) throw skipped;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (error === skipped) {
|
|
191
|
+
if (0 === wrapperDepth) count--;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (!hasAggregate) throw error;
|
|
195
|
+
exception = this.coerceFallback(ctx);
|
|
196
|
+
}
|
|
197
|
+
if (!errors || count >= MAX_EXCEPTIONS) return exception;
|
|
198
|
+
let length;
|
|
199
|
+
try {
|
|
200
|
+
length = errors.length;
|
|
201
|
+
} catch {
|
|
202
|
+
return exception;
|
|
132
203
|
}
|
|
204
|
+
if (!Number.isInteger(length) || length < 0 || length > 0xffffffff) return exception;
|
|
205
|
+
const children = [];
|
|
206
|
+
for(let index = 0; count < MAX_EXCEPTIONS && memberInspections < MAX_AGGREGATE_MEMBER_INSPECTIONS && index < length; index++){
|
|
207
|
+
memberInspections++;
|
|
208
|
+
let child;
|
|
209
|
+
try {
|
|
210
|
+
child = ctx.next(errors[index]);
|
|
211
|
+
} catch {
|
|
212
|
+
count++;
|
|
213
|
+
child = this.coerceFallback(createContext(depth + 1));
|
|
214
|
+
}
|
|
215
|
+
if (child) children.push(child);
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
...exception,
|
|
219
|
+
errors: children
|
|
220
|
+
};
|
|
133
221
|
};
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
222
|
+
const createContext = (depth, wrapperDepth = 0)=>({
|
|
223
|
+
...hint,
|
|
224
|
+
syntheticException: 0 == depth ? hint.syntheticException : void 0,
|
|
225
|
+
mechanism: 0 == depth ? mechanism : {},
|
|
226
|
+
apply: (input)=>{
|
|
227
|
+
const exception = coerce(input, depth, wrapperDepth + 1);
|
|
228
|
+
if (!exception) throw skipped;
|
|
229
|
+
return exception;
|
|
230
|
+
},
|
|
231
|
+
next: (input)=>coerce(input, depth + 1)
|
|
232
|
+
});
|
|
233
|
+
const context = createContext(depth);
|
|
234
|
+
return {
|
|
235
|
+
...context,
|
|
236
|
+
apply: (input)=>coerce(input, depth) ?? this.coerceFallback(context)
|
|
140
237
|
};
|
|
141
|
-
return context;
|
|
142
238
|
}
|
|
143
239
|
}
|
|
144
240
|
exports.ErrorPropertiesBuilder = __webpack_exports__.ErrorPropertiesBuilder;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { isArray } from "../utils/index.mjs";
|
|
1
|
+
import { isArray, isError } from "../utils/index.mjs";
|
|
2
2
|
import { getFilenameToChunkIdMap } from "./chunk-ids.mjs";
|
|
3
|
-
const
|
|
3
|
+
const MAX_EXCEPTIONS = 50;
|
|
4
|
+
const MAX_AGGREGATE_MEMBER_INSPECTIONS = 1000;
|
|
5
|
+
const MAX_ERROR_PROTOTYPE_DEPTH = 100;
|
|
6
|
+
const MAX_WRAPPER_RECURSION = 4;
|
|
4
7
|
class ErrorPropertiesBuilder {
|
|
5
8
|
constructor(coercers, stackParser, modifiers = []){
|
|
6
9
|
this.coercers = coercers;
|
|
@@ -39,11 +42,14 @@ class ErrorPropertiesBuilder {
|
|
|
39
42
|
let cause;
|
|
40
43
|
if (null != err.cause) cause = this.parseStacktrace(err.cause, ctx);
|
|
41
44
|
let stack;
|
|
42
|
-
if ('' != err.stack && null != err.stack)
|
|
45
|
+
if ('' != err.stack && null != err.stack) try {
|
|
46
|
+
stack = this.applyChunkIds(this.stackParser(err.stack, err.synthetic ? ctx.skipFirstLines : 0), ctx.chunkIdMap);
|
|
47
|
+
} catch {}
|
|
43
48
|
return {
|
|
44
49
|
...err,
|
|
45
50
|
cause,
|
|
46
|
-
stack
|
|
51
|
+
stack,
|
|
52
|
+
errors: err.errors?.map((child)=>this.parseStacktrace(child, ctx))
|
|
47
53
|
};
|
|
48
54
|
}
|
|
49
55
|
applyChunkIds(frames, chunkIdMap) {
|
|
@@ -62,26 +68,39 @@ class ErrorPropertiesBuilder {
|
|
|
62
68
|
return newFrames;
|
|
63
69
|
}
|
|
64
70
|
convertToExceptionList(exceptionWithStack, mechanism) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
type: mechanism.type
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
const exceptionList = [];
|
|
72
|
+
const append = (exception, parentId, source)=>{
|
|
73
|
+
const exceptionId = exceptionList.length;
|
|
74
|
+
const entryMechanism = void 0 === parentId ? {
|
|
75
|
+
type: 'string' == typeof mechanism.type && mechanism.type.length > 0 ? mechanism.type : 'generic',
|
|
76
|
+
...'boolean' == typeof mechanism.handled ? {
|
|
77
|
+
handled: mechanism.handled
|
|
78
|
+
} : void 0 === mechanism.handled ? {
|
|
79
|
+
handled: true
|
|
80
|
+
} : {},
|
|
81
|
+
synthetic: 'boolean' == typeof mechanism.synthetic ? mechanism.synthetic : exception.synthetic,
|
|
82
|
+
exception_id: exceptionId
|
|
83
|
+
} : {
|
|
84
|
+
type: 'chained',
|
|
85
|
+
source,
|
|
86
|
+
synthetic: exception.synthetic,
|
|
87
|
+
exception_id: exceptionId,
|
|
88
|
+
parent_id: parentId
|
|
89
|
+
};
|
|
90
|
+
const currentException = {
|
|
91
|
+
type: exception.type,
|
|
92
|
+
value: exception.value,
|
|
93
|
+
mechanism: entryMechanism
|
|
94
|
+
};
|
|
95
|
+
if (exception.stack) currentException.stacktrace = {
|
|
96
|
+
type: 'raw',
|
|
97
|
+
frames: exception.stack
|
|
98
|
+
};
|
|
99
|
+
exceptionList.push(currentException);
|
|
100
|
+
if (exception.cause) append(exception.cause, exceptionId, 'cause');
|
|
101
|
+
for (const child of exception.errors ?? [])append(child, exceptionId, 'member');
|
|
77
102
|
};
|
|
78
|
-
|
|
79
|
-
currentException
|
|
80
|
-
];
|
|
81
|
-
if (null != exceptionWithStack.cause) exceptionList.push(...this.convertToExceptionList(exceptionWithStack.cause, {
|
|
82
|
-
...mechanism,
|
|
83
|
-
handled: true
|
|
84
|
-
}));
|
|
103
|
+
append(exceptionWithStack);
|
|
85
104
|
return exceptionList;
|
|
86
105
|
}
|
|
87
106
|
buildParsingContext(hint) {
|
|
@@ -91,22 +110,99 @@ class ErrorPropertiesBuilder {
|
|
|
91
110
|
};
|
|
92
111
|
return context;
|
|
93
112
|
}
|
|
113
|
+
getAggregateErrors(input) {
|
|
114
|
+
try {
|
|
115
|
+
if (isError(input)) {
|
|
116
|
+
let prototype = Object.getPrototypeOf(input);
|
|
117
|
+
for(let depth = 0; prototype && depth < MAX_ERROR_PROTOTYPE_DEPTH; depth++){
|
|
118
|
+
const constructor = Object.getOwnPropertyDescriptor(prototype, 'constructor')?.value;
|
|
119
|
+
if ('function' == typeof constructor && 'AggregateError' === constructor.name) {
|
|
120
|
+
const errors = input.errors;
|
|
121
|
+
return isArray(errors) ? errors : void 0;
|
|
122
|
+
}
|
|
123
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} catch {}
|
|
127
|
+
}
|
|
94
128
|
buildCoercingContext(mechanism, hint, depth = 0) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
129
|
+
let count = 0;
|
|
130
|
+
let memberInspections = 0;
|
|
131
|
+
let hasAggregate = false;
|
|
132
|
+
const seen = new Set();
|
|
133
|
+
const wrappers = [];
|
|
134
|
+
const skipped = {};
|
|
135
|
+
const coerce = (input, depth, wrapperDepth = 0)=>{
|
|
136
|
+
const ctx = createContext(depth, wrapperDepth);
|
|
137
|
+
const forward = ctx.apply;
|
|
138
|
+
ctx.apply = (nextInput)=>{
|
|
139
|
+
wrappers.push(input);
|
|
140
|
+
try {
|
|
141
|
+
return forward(nextInput);
|
|
142
|
+
} finally{
|
|
143
|
+
wrappers.pop();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
if (wrapperDepth > MAX_WRAPPER_RECURSION || wrapperDepth > 0 && -1 !== wrappers.indexOf(input)) return this.coerceFallback(ctx);
|
|
147
|
+
const isReference = 'object' == typeof input && null !== input || 'function' == typeof input;
|
|
148
|
+
if (0 === wrapperDepth && count >= MAX_EXCEPTIONS || isReference && seen.has(input)) return;
|
|
149
|
+
if (isReference) seen.add(input);
|
|
150
|
+
if (0 === wrapperDepth) count++;
|
|
151
|
+
const errors = this.getAggregateErrors(input);
|
|
152
|
+
hasAggregate ||= !!errors;
|
|
153
|
+
let exception;
|
|
154
|
+
try {
|
|
155
|
+
exception = this.applyCoercers(input, ctx);
|
|
156
|
+
if (!exception) throw skipped;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (error === skipped) {
|
|
159
|
+
if (0 === wrapperDepth) count--;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!hasAggregate) throw error;
|
|
163
|
+
exception = this.coerceFallback(ctx);
|
|
164
|
+
}
|
|
165
|
+
if (!errors || count >= MAX_EXCEPTIONS) return exception;
|
|
166
|
+
let length;
|
|
167
|
+
try {
|
|
168
|
+
length = errors.length;
|
|
169
|
+
} catch {
|
|
170
|
+
return exception;
|
|
100
171
|
}
|
|
172
|
+
if (!Number.isInteger(length) || length < 0 || length > 0xffffffff) return exception;
|
|
173
|
+
const children = [];
|
|
174
|
+
for(let index = 0; count < MAX_EXCEPTIONS && memberInspections < MAX_AGGREGATE_MEMBER_INSPECTIONS && index < length; index++){
|
|
175
|
+
memberInspections++;
|
|
176
|
+
let child;
|
|
177
|
+
try {
|
|
178
|
+
child = ctx.next(errors[index]);
|
|
179
|
+
} catch {
|
|
180
|
+
count++;
|
|
181
|
+
child = this.coerceFallback(createContext(depth + 1));
|
|
182
|
+
}
|
|
183
|
+
if (child) children.push(child);
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
...exception,
|
|
187
|
+
errors: children
|
|
188
|
+
};
|
|
101
189
|
};
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
190
|
+
const createContext = (depth, wrapperDepth = 0)=>({
|
|
191
|
+
...hint,
|
|
192
|
+
syntheticException: 0 == depth ? hint.syntheticException : void 0,
|
|
193
|
+
mechanism: 0 == depth ? mechanism : {},
|
|
194
|
+
apply: (input)=>{
|
|
195
|
+
const exception = coerce(input, depth, wrapperDepth + 1);
|
|
196
|
+
if (!exception) throw skipped;
|
|
197
|
+
return exception;
|
|
198
|
+
},
|
|
199
|
+
next: (input)=>coerce(input, depth + 1)
|
|
200
|
+
});
|
|
201
|
+
const context = createContext(depth);
|
|
202
|
+
return {
|
|
203
|
+
...context,
|
|
204
|
+
apply: (input)=>coerce(input, depth) ?? this.coerceFallback(context)
|
|
108
205
|
};
|
|
109
|
-
return context;
|
|
110
206
|
}
|
|
111
207
|
}
|
|
112
208
|
export { ErrorPropertiesBuilder };
|
|
@@ -32,8 +32,10 @@ export interface Exception {
|
|
|
32
32
|
}
|
|
33
33
|
export type ExceptionList = Exception[];
|
|
34
34
|
export interface Mechanism {
|
|
35
|
+
exception_id?: number;
|
|
36
|
+
parent_id?: number;
|
|
35
37
|
handled?: boolean;
|
|
36
|
-
type?:
|
|
38
|
+
type?: string;
|
|
37
39
|
source?: string;
|
|
38
40
|
synthetic?: boolean;
|
|
39
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/error-tracking/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAKxC,eAAO,MAAM,cAAc,gEAAiE,CAAA;AAC5F,MAAM,CAAC,OAAO,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAEnE,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC9B,kBAAkB,CAAC,EAAE,KAAK,GAAG,IAAI,CAAA;IACjC,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,mCAAmC,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IAAI,OAAO,CAAC,CAAC,EAAE,aAAa,GAAG,SAAS,EAAE,eAAe,CAAC,CAAA;AAE5F,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,KAAK,CAAC,EAAE,UAAU,EAAE,CAAA;IACpB,KAAK,CAAC,EAAE,eAAe,CAAA;CACxB"}
|
package/package.json
CHANGED
|
@@ -12,11 +12,12 @@ export class ErrorCoercer implements ErrorTrackingCoercer<Error> {
|
|
|
12
12
|
// `TypeError`). Fall back to the synthetic exception captured at the call
|
|
13
13
|
// site so the frames still point at the caller. Mark it synthetic so the
|
|
14
14
|
// parser trims the SDK's own frames.
|
|
15
|
-
const
|
|
15
|
+
const replacementStack = stack === undefined ? ctx.syntheticException?.stack : undefined
|
|
16
|
+
const synthetic = !!replacementStack
|
|
16
17
|
return {
|
|
17
18
|
type: this.getType(err),
|
|
18
19
|
value: this.getMessage(err, ctx),
|
|
19
|
-
stack: stack ??
|
|
20
|
+
stack: stack ?? replacementStack,
|
|
20
21
|
cause: err.cause ? ctx.next(err.cause) : undefined,
|
|
21
22
|
synthetic,
|
|
22
23
|
}
|
|
@@ -37,6 +38,15 @@ export class ErrorCoercer implements ErrorTrackingCoercer<Error> {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
private getStack(err: Error & { stacktrace?: string }): string | undefined {
|
|
40
|
-
|
|
41
|
+
try {
|
|
42
|
+
const stacktrace = err.stacktrace
|
|
43
|
+
if (typeof stacktrace === 'string' && stacktrace.length > 0) {
|
|
44
|
+
return stacktrace
|
|
45
|
+
}
|
|
46
|
+
const stack = err.stack
|
|
47
|
+
return typeof stack === 'string' && stack.length > 0 ? stack : undefined
|
|
48
|
+
} catch {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
}
|