@posthog/core 1.48.3 → 1.48.4
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 +4 -2
- package/dist/error-tracking/coercers/error-coercer.mjs +4 -2
- package/package.json +1 -1
- package/src/error-tracking/coercers/error-coercer.ts +8 -2
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +15 -0
|
@@ -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;IAgBvD,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,QAAQ;CAGjB"}
|
|
@@ -32,12 +32,14 @@ class ErrorCoercer {
|
|
|
32
32
|
return (0, type_utils_js_namespaceObject.isError)(err);
|
|
33
33
|
}
|
|
34
34
|
coerce(err, ctx) {
|
|
35
|
+
const stack = this.getStack(err);
|
|
36
|
+
const synthetic = void 0 === stack;
|
|
35
37
|
return {
|
|
36
38
|
type: this.getType(err),
|
|
37
39
|
value: this.getMessage(err, ctx),
|
|
38
|
-
stack:
|
|
40
|
+
stack: stack ?? ctx.syntheticException?.stack,
|
|
39
41
|
cause: err.cause ? ctx.next(err.cause) : void 0,
|
|
40
|
-
synthetic
|
|
42
|
+
synthetic
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
getType(err) {
|
|
@@ -4,12 +4,14 @@ class ErrorCoercer {
|
|
|
4
4
|
return isError(err);
|
|
5
5
|
}
|
|
6
6
|
coerce(err, ctx) {
|
|
7
|
+
const stack = this.getStack(err);
|
|
8
|
+
const synthetic = void 0 === stack;
|
|
7
9
|
return {
|
|
8
10
|
type: this.getType(err),
|
|
9
11
|
value: this.getMessage(err, ctx),
|
|
10
|
-
stack:
|
|
12
|
+
stack: stack ?? ctx.syntheticException?.stack,
|
|
11
13
|
cause: err.cause ? ctx.next(err.cause) : void 0,
|
|
12
|
-
synthetic
|
|
14
|
+
synthetic
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
getType(err) {
|
package/package.json
CHANGED
|
@@ -7,12 +7,18 @@ export class ErrorCoercer implements ErrorTrackingCoercer<Error> {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
coerce(err: Error, ctx: CoercingContext): ExceptionLike {
|
|
10
|
+
const stack = this.getStack(err)
|
|
11
|
+
// Some errors carry no usable stack (for example a Firefox network `fetch`
|
|
12
|
+
// `TypeError`). Fall back to the synthetic exception captured at the call
|
|
13
|
+
// site so the frames still point at the caller. Mark it synthetic so the
|
|
14
|
+
// parser trims the SDK's own frames.
|
|
15
|
+
const synthetic = stack === undefined
|
|
10
16
|
return {
|
|
11
17
|
type: this.getType(err),
|
|
12
18
|
value: this.getMessage(err, ctx),
|
|
13
|
-
stack:
|
|
19
|
+
stack: stack ?? ctx.syntheticException?.stack,
|
|
14
20
|
cause: err.cause ? ctx.next(err.cause) : undefined,
|
|
15
|
-
synthetic
|
|
21
|
+
synthetic,
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
|
|
@@ -112,6 +112,21 @@ describe('ErrorPropertiesBuilder', () => {
|
|
|
112
112
|
})
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
+
it('should fall back to the synthetic stack when the error has no stack', () => {
|
|
116
|
+
// Firefox rejects a network `fetch` with a `TypeError` that carries no
|
|
117
|
+
// stack, so the frames must come from the synthetic exception instead.
|
|
118
|
+
const errorObject = new CustomTestError('My special error')
|
|
119
|
+
errorObject.stack = ''
|
|
120
|
+
const syntheticError = new Error()
|
|
121
|
+
const exception = coerceInput(errorObject, syntheticError)
|
|
122
|
+
expect(exception).toMatchObject({
|
|
123
|
+
type: 'CustomTestError',
|
|
124
|
+
value: 'My special error',
|
|
125
|
+
stack: syntheticError.stack,
|
|
126
|
+
synthetic: true,
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
115
130
|
it('should preserve a cross-realm error', () => {
|
|
116
131
|
const crossRealmError = runInNewContext(
|
|
117
132
|
`new TypeError('cross-realm error', {
|