posthog-node 5.9.0 → 5.9.2

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.
Files changed (74) hide show
  1. package/dist/client.d.ts.map +1 -1
  2. package/dist/client.js +1 -2
  3. package/dist/client.mjs +1 -2
  4. package/dist/entrypoints/index.edge.d.ts.map +1 -1
  5. package/dist/entrypoints/index.edge.js +12 -5
  6. package/dist/entrypoints/index.edge.mjs +10 -3
  7. package/dist/entrypoints/index.node.d.ts.map +1 -1
  8. package/dist/entrypoints/index.node.js +23 -15
  9. package/dist/entrypoints/index.node.mjs +14 -6
  10. package/dist/extensions/error-tracking/autocapture.d.ts +3 -3
  11. package/dist/extensions/error-tracking/autocapture.d.ts.map +1 -1
  12. package/dist/extensions/error-tracking/index.d.ts +3 -4
  13. package/dist/extensions/error-tracking/index.d.ts.map +1 -1
  14. package/dist/extensions/error-tracking/index.js +3 -3
  15. package/dist/extensions/error-tracking/index.mjs +3 -3
  16. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts +5 -0
  17. package/dist/extensions/error-tracking/modifiers/context-lines.node.d.ts.map +1 -0
  18. package/dist/extensions/error-tracking/{context-lines.node.js → modifiers/context-lines.node.js} +3 -3
  19. package/dist/extensions/error-tracking/{context-lines.node.mjs → modifiers/context-lines.node.mjs} +3 -3
  20. package/dist/extensions/error-tracking/modifiers/module.node.d.ts +3 -0
  21. package/dist/extensions/error-tracking/modifiers/module.node.d.ts.map +1 -0
  22. package/dist/extensions/error-tracking/{get-module.node.js → modifiers/module.node.js} +10 -3
  23. package/dist/extensions/error-tracking/{get-module.node.mjs → modifiers/module.node.mjs} +8 -1
  24. package/dist/extensions/express.d.ts.map +1 -1
  25. package/dist/extensions/sentry-integration.d.ts +3 -3
  26. package/dist/extensions/sentry-integration.d.ts.map +1 -1
  27. package/dist/version.d.ts +1 -1
  28. package/dist/version.js +1 -1
  29. package/dist/version.mjs +1 -1
  30. package/package.json +2 -2
  31. package/src/client.ts +1 -1
  32. package/src/entrypoints/index.edge.ts +11 -4
  33. package/src/entrypoints/index.node.ts +14 -5
  34. package/src/extensions/error-tracking/autocapture.ts +6 -4
  35. package/src/extensions/error-tracking/index.ts +10 -9
  36. package/src/extensions/error-tracking/{context-lines.node.ts → modifiers/context-lines.node.ts} +23 -11
  37. package/src/extensions/error-tracking/{get-module.node.ts → modifiers/module.node.ts} +12 -1
  38. package/src/extensions/express.ts +2 -1
  39. package/src/extensions/sentry-integration.ts +4 -4
  40. package/src/version.ts +1 -1
  41. package/dist/extensions/error-tracking/chunk-ids.d.ts +0 -5
  42. package/dist/extensions/error-tracking/chunk-ids.d.ts.map +0 -1
  43. package/dist/extensions/error-tracking/chunk-ids.js +0 -68
  44. package/dist/extensions/error-tracking/chunk-ids.mjs +0 -34
  45. package/dist/extensions/error-tracking/context-lines.node.d.ts +0 -5
  46. package/dist/extensions/error-tracking/context-lines.node.d.ts.map +0 -1
  47. package/dist/extensions/error-tracking/error-conversion.d.ts +0 -4
  48. package/dist/extensions/error-tracking/error-conversion.d.ts.map +0 -1
  49. package/dist/extensions/error-tracking/error-conversion.js +0 -183
  50. package/dist/extensions/error-tracking/error-conversion.mjs +0 -146
  51. package/dist/extensions/error-tracking/get-module.node.d.ts +0 -3
  52. package/dist/extensions/error-tracking/get-module.node.d.ts.map +0 -1
  53. package/dist/extensions/error-tracking/reduceable-cache.d.ts +0 -13
  54. package/dist/extensions/error-tracking/reduceable-cache.d.ts.map +0 -1
  55. package/dist/extensions/error-tracking/reduceable-cache.js +0 -57
  56. package/dist/extensions/error-tracking/reduceable-cache.mjs +0 -23
  57. package/dist/extensions/error-tracking/stack-parser.d.ts +0 -3
  58. package/dist/extensions/error-tracking/stack-parser.d.ts.map +0 -1
  59. package/dist/extensions/error-tracking/stack-parser.js +0 -148
  60. package/dist/extensions/error-tracking/stack-parser.mjs +0 -114
  61. package/dist/extensions/error-tracking/type-checking.d.ts +0 -8
  62. package/dist/extensions/error-tracking/type-checking.d.ts.map +0 -1
  63. package/dist/extensions/error-tracking/type-checking.js +0 -80
  64. package/dist/extensions/error-tracking/type-checking.mjs +0 -31
  65. package/dist/extensions/error-tracking/types.d.ts +0 -61
  66. package/dist/extensions/error-tracking/types.d.ts.map +0 -1
  67. package/dist/extensions/error-tracking/types.js +0 -43
  68. package/dist/extensions/error-tracking/types.mjs +0 -9
  69. package/src/extensions/error-tracking/chunk-ids.ts +0 -58
  70. package/src/extensions/error-tracking/error-conversion.ts +0 -291
  71. package/src/extensions/error-tracking/reduceable-cache.ts +0 -39
  72. package/src/extensions/error-tracking/stack-parser.ts +0 -212
  73. package/src/extensions/error-tracking/type-checking.ts +0 -40
  74. package/src/extensions/error-tracking/types.ts +0 -71
@@ -1,11 +1,10 @@
1
- import { EventHint, StackFrameModifierFn, StackParser } from './types'
2
1
  import { addUncaughtExceptionListener, addUnhandledRejectionListener } from './autocapture'
3
- import { PostHogBackendClient } from '../../client'
2
+ import { PostHogBackendClient } from '@/client'
4
3
  import { uuidv7 } from '@posthog/core'
5
- import { propertiesFromUnknownInput } from './error-conversion'
6
- import { EventMessage, PostHogOptions } from '../../types'
4
+ import { EventMessage, PostHogOptions } from '@/types'
7
5
  import type { Logger } from '@posthog/core'
8
6
  import { BucketedRateLimiter } from '@posthog/core'
7
+ import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
9
8
 
10
9
  const SHUTDOWN_TIMEOUT = 2000
11
10
 
@@ -15,8 +14,7 @@ export default class ErrorTracking {
15
14
  private _rateLimiter: BucketedRateLimiter<string>
16
15
  private _logger: Logger
17
16
 
18
- static stackParser: StackParser
19
- static frameModifiers: StackFrameModifierFn[]
17
+ static errorPropertiesBuilder: CoreErrorTracking.ErrorPropertiesBuilder
20
18
 
21
19
  constructor(client: PostHogBackendClient, options: PostHogOptions, _logger: Logger) {
22
20
  this.client = client
@@ -38,7 +36,7 @@ export default class ErrorTracking {
38
36
 
39
37
  static async buildEventMessage(
40
38
  error: unknown,
41
- hint: EventHint,
39
+ hint: CoreErrorTracking.EventHint,
42
40
  distinctId?: string,
43
41
  additionalProperties?: Record<string | number, any>
44
42
  ): Promise<EventMessage> {
@@ -50,7 +48,10 @@ export default class ErrorTracking {
50
48
  properties.$process_person_profile = false
51
49
  }
52
50
 
53
- const exceptionProperties = await propertiesFromUnknownInput(this.stackParser, this.frameModifiers, error, hint)
51
+ const exceptionProperties = this.errorPropertiesBuilder.buildFromUnknown(error, hint)
52
+ exceptionProperties.$exception_list = await this.errorPropertiesBuilder.modifyFrames(
53
+ exceptionProperties.$exception_list
54
+ )
54
55
 
55
56
  return {
56
57
  event: '$exception',
@@ -69,7 +70,7 @@ export default class ErrorTracking {
69
70
  }
70
71
  }
71
72
 
72
- private async onException(exception: unknown, hint: EventHint): Promise<void> {
73
+ private onException(exception: unknown, hint: CoreErrorTracking.EventHint): void {
73
74
  this.client.addPendingPromise(
74
75
  (async () => {
75
76
  const eventMessage = await ErrorTracking.buildEventMessage(exception, hint)
@@ -1,13 +1,12 @@
1
1
  // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2
2
  // Licensed under the MIT License
3
3
 
4
- import { StackFrame } from './types'
5
- import { ReduceableCache } from './reduceable-cache'
4
+ import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
6
5
  import { createReadStream } from 'node:fs'
7
6
  import { createInterface } from 'node:readline'
8
7
 
9
- const LRU_FILE_CONTENTS_CACHE = new ReduceableCache<string, Record<number, string>>(25)
10
- const LRU_FILE_CONTENTS_FS_READ_FAILED = new ReduceableCache<string, 1>(20)
8
+ const LRU_FILE_CONTENTS_CACHE = new CoreErrorTracking.ReduceableCache<string, Record<number, string>>(25)
9
+ const LRU_FILE_CONTENTS_FS_READ_FAILED = new CoreErrorTracking.ReduceableCache<string, 1>(20)
11
10
  const DEFAULT_LINES_OF_CONTEXT = 7
12
11
  // Determines the upper bound of lineno/colno that we will attempt to read. Large colno values are likely to be
13
12
  // minified code while large lineno values are likely to be bundled code.
@@ -17,7 +16,9 @@ export const MAX_CONTEXTLINES_LINENO: number = 10000
17
16
 
18
17
  type ReadlineRange = [start: number, end: number]
19
18
 
20
- export async function addSourceContext(frames: StackFrame[]): Promise<StackFrame[]> {
19
+ export async function addSourceContext(
20
+ frames: CoreErrorTracking.StackFrame[]
21
+ ): Promise<CoreErrorTracking.StackFrame[]> {
21
22
  // keep a lookup map of which files we've already enqueued to read,
22
23
  // so we don't enqueue the same file multiple times which would cause multiple i/o reads
23
24
  const filesToLines: Record<string, number[]> = {}
@@ -25,7 +26,7 @@ export async function addSourceContext(frames: StackFrame[]): Promise<StackFrame
25
26
  // Maps preserve insertion order, so we iterate in reverse, starting at the
26
27
  // outermost frame and closer to where the exception has occurred (poor mans priority)
27
28
  for (let i = frames.length - 1; i >= 0; i--) {
28
- const frame: StackFrame | undefined = frames[i]
29
+ const frame: CoreErrorTracking.StackFrame | undefined = frames[i]
29
30
  const filename = frame?.filename
30
31
 
31
32
  if (
@@ -171,7 +172,10 @@ function getContextLinesFromFile(path: string, ranges: ReadlineRange[], output:
171
172
  }
172
173
 
173
174
  /** Adds context lines to frames */
174
- function addSourceContextToFrames(frames: StackFrame[], cache: ReduceableCache<string, Record<number, string>>): void {
175
+ function addSourceContextToFrames(
176
+ frames: CoreErrorTracking.StackFrame[],
177
+ cache: CoreErrorTracking.ReduceableCache<string, Record<number, string>>
178
+ ): void {
175
179
  for (const frame of frames) {
176
180
  // Only add context if we have a filename and it hasn't already been added
177
181
  if (frame.filename && frame.context_line === undefined && typeof frame.lineno === 'number') {
@@ -188,7 +192,11 @@ function addSourceContextToFrames(frames: StackFrame[], cache: ReduceableCache<s
188
192
  /**
189
193
  * Resolves context lines before and after the given line number and appends them to the frame;
190
194
  */
191
- function addContextToFrame(lineno: number, frame: StackFrame, contents: Record<number, string> | undefined): void {
195
+ function addContextToFrame(
196
+ lineno: number,
197
+ frame: CoreErrorTracking.StackFrame,
198
+ contents: Record<number, string> | undefined
199
+ ): void {
192
200
  // When there is no line number in the frame, attaching context is nonsensical and will even break grouping.
193
201
  // We already check for lineno before calling this, but since StackFrame lineno is optional, we check it again.
194
202
  if (frame.lineno === undefined || contents === undefined) {
@@ -234,7 +242,7 @@ function addContextToFrame(lineno: number, frame: StackFrame, contents: Record<n
234
242
  * Clears the context lines from a frame, used to reset a frame to its original state
235
243
  * if we fail to resolve all context lines for it.
236
244
  */
237
- function clearLineContext(frame: StackFrame): void {
245
+ function clearLineContext(frame: CoreErrorTracking.StackFrame): void {
238
246
  delete frame.pre_context
239
247
  delete frame.context_line
240
248
  delete frame.post_context
@@ -261,7 +269,7 @@ function shouldSkipContextLinesForFile(path: string): boolean {
261
269
  /**
262
270
  * Determines if we should skip contextlines based off the max lineno and colno values.
263
271
  */
264
- function shouldSkipContextLinesForFrame(frame: StackFrame): boolean {
272
+ function shouldSkipContextLinesForFrame(frame: CoreErrorTracking.StackFrame): boolean {
265
273
  if (frame.lineno !== undefined && frame.lineno > MAX_CONTEXTLINES_LINENO) {
266
274
  return true
267
275
  }
@@ -346,7 +354,11 @@ function makeRangeEnd(line: number): number {
346
354
  /**
347
355
  * Get or init map value
348
356
  */
349
- function emplace<T extends ReduceableCache<K, V>, K extends string, V>(map: T, key: K, contents: V): V {
357
+ function emplace<T extends CoreErrorTracking.ReduceableCache<K, V>, K extends string, V>(
358
+ map: T,
359
+ key: K,
360
+ contents: V
361
+ ): V {
350
362
  const value = map.get(key)
351
363
 
352
364
  if (value === undefined) {
@@ -1,10 +1,21 @@
1
1
  // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2
2
  // Licensed under the MIT License
3
3
 
4
+ import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
4
5
  import { posix, sep, dirname } from 'path'
5
6
 
7
+ export function createModulerModifier() {
8
+ const getModuleFromFileName = createGetModuleFromFilename()
9
+ return async (frames: CoreErrorTracking.StackFrame[]): Promise<CoreErrorTracking.StackFrame[]> => {
10
+ for (const frame of frames) {
11
+ frame.module = getModuleFromFileName(frame.filename)
12
+ }
13
+ return frames
14
+ }
15
+ }
16
+
6
17
  /** Creates a function that gets the module name from a filename */
7
- export function createGetModuleFromFilename(
18
+ function createGetModuleFromFilename(
8
19
  basePath: string = process.argv[1] ? dirname(process.argv[1]) : process.cwd(),
9
20
  isWindows: boolean = sep === '\\'
10
21
  ): (filename: string | undefined) => string | undefined {
@@ -2,6 +2,7 @@ import type * as http from 'node:http'
2
2
  import { uuidv7 } from '@posthog/core'
3
3
  import ErrorTracking from './error-tracking'
4
4
  import { PostHogBackendClient } from '../client'
5
+ import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
5
6
 
6
7
  type ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void
7
8
 
@@ -28,7 +29,7 @@ export function setupExpressErrorHandler(
28
29
  }
29
30
  ): void {
30
31
  app.use((error: MiddlewareError, _, __, next: (error: MiddlewareError) => void): void => {
31
- const hint = { mechanism: { type: 'middleware', handled: false } }
32
+ const hint: CoreErrorTracking.EventHint = { mechanism: { type: 'middleware', handled: false } }
32
33
  // Given stateless nature of Node SDK we capture exceptions using personless processing
33
34
  // when no user can be determined e.g. in the case of exception autocapture
34
35
  ErrorTracking.buildEventMessage(error, hint, uuidv7(), { $process_person_profile: false }).then((msg) =>
@@ -23,7 +23,7 @@
23
23
  * @param {boolean} [sendExceptionsToPostHog] Optional: capture exceptions as events in PostHog (default: true)
24
24
  */
25
25
 
26
- import { SeverityLevel } from './error-tracking/types'
26
+ import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
27
27
  import { type PostHogBackendClient } from '../client'
28
28
 
29
29
  // NOTE - we can't import from @sentry/types because it changes frequently and causes clashes
@@ -70,7 +70,7 @@ export type SentryIntegrationOptions = {
70
70
  organization?: string
71
71
  projectId?: number
72
72
  prefix?: string
73
- severityAllowList?: SeverityLevel[] | '*'
73
+ severityAllowList?: CoreErrorTracking.SeverityLevel[] | '*'
74
74
  sendExceptionsToPostHog?: boolean
75
75
  }
76
76
 
@@ -129,7 +129,7 @@ export function createEventProcessor(
129
129
  $exception_type: any
130
130
  $exception_list: any
131
131
  $exception_personURL: string
132
- $exception_level: SeverityLevel
132
+ $exception_level: CoreErrorTracking.SeverityLevel
133
133
  } = {
134
134
  // PostHog Exception Properties,
135
135
  $exception_message: exceptions[0]?.value || event.message,
@@ -192,7 +192,7 @@ export class PostHogSentryIntegration implements _SentryIntegrationClass {
192
192
  _posthog: PostHogBackendClient,
193
193
  organization?: string,
194
194
  prefix?: string,
195
- severityAllowList?: SeverityLevel[] | '*',
195
+ severityAllowList?: CoreErrorTracking.SeverityLevel[] | '*',
196
196
  sendExceptionsToPostHog?: boolean
197
197
  ) {
198
198
  // setupOnce gets called by Sentry when it intializes the plugin
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.9.0'
1
+ export const version = '5.9.2'
@@ -1,5 +0,0 @@
1
- import type { StackParser } from './types';
2
- type ChunkIdMapType = Record<string, string>;
3
- export declare function getFilenameToChunkIdMap(stackParser: StackParser): ChunkIdMapType | null;
4
- export {};
5
- //# sourceMappingURL=chunk-ids.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunk-ids.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/chunk-ids.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK1C,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAM5C,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,cAAc,GAAG,IAAI,CA2CvF"}
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- getFilenameToChunkIdMap: ()=>getFilenameToChunkIdMap
28
- });
29
- let parsedStackResults;
30
- let lastKeysCount;
31
- let cachedFilenameChunkIds;
32
- function getFilenameToChunkIdMap(stackParser) {
33
- const chunkIdMap = globalThis._posthogChunkIds;
34
- if (!chunkIdMap) return null;
35
- const chunkIdKeys = Object.keys(chunkIdMap);
36
- if (cachedFilenameChunkIds && chunkIdKeys.length === lastKeysCount) return cachedFilenameChunkIds;
37
- lastKeysCount = chunkIdKeys.length;
38
- cachedFilenameChunkIds = chunkIdKeys.reduce((acc, stackKey)=>{
39
- if (!parsedStackResults) parsedStackResults = {};
40
- const result = parsedStackResults[stackKey];
41
- if (result) acc[result[0]] = result[1];
42
- else {
43
- const parsedStack = stackParser(stackKey);
44
- for(let i = parsedStack.length - 1; i >= 0; i--){
45
- const stackFrame = parsedStack[i];
46
- const filename = stackFrame?.filename;
47
- const chunkId = chunkIdMap[stackKey];
48
- if (filename && chunkId) {
49
- acc[filename] = chunkId;
50
- parsedStackResults[stackKey] = [
51
- filename,
52
- chunkId
53
- ];
54
- break;
55
- }
56
- }
57
- }
58
- return acc;
59
- }, {});
60
- return cachedFilenameChunkIds;
61
- }
62
- exports.getFilenameToChunkIdMap = __webpack_exports__.getFilenameToChunkIdMap;
63
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
64
- "getFilenameToChunkIdMap"
65
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
66
- Object.defineProperty(exports, '__esModule', {
67
- value: true
68
- });
@@ -1,34 +0,0 @@
1
- let parsedStackResults;
2
- let lastKeysCount;
3
- let cachedFilenameChunkIds;
4
- function getFilenameToChunkIdMap(stackParser) {
5
- const chunkIdMap = globalThis._posthogChunkIds;
6
- if (!chunkIdMap) return null;
7
- const chunkIdKeys = Object.keys(chunkIdMap);
8
- if (cachedFilenameChunkIds && chunkIdKeys.length === lastKeysCount) return cachedFilenameChunkIds;
9
- lastKeysCount = chunkIdKeys.length;
10
- cachedFilenameChunkIds = chunkIdKeys.reduce((acc, stackKey)=>{
11
- if (!parsedStackResults) parsedStackResults = {};
12
- const result = parsedStackResults[stackKey];
13
- if (result) acc[result[0]] = result[1];
14
- else {
15
- const parsedStack = stackParser(stackKey);
16
- for(let i = parsedStack.length - 1; i >= 0; i--){
17
- const stackFrame = parsedStack[i];
18
- const filename = stackFrame?.filename;
19
- const chunkId = chunkIdMap[stackKey];
20
- if (filename && chunkId) {
21
- acc[filename] = chunkId;
22
- parsedStackResults[stackKey] = [
23
- filename,
24
- chunkId
25
- ];
26
- break;
27
- }
28
- }
29
- }
30
- return acc;
31
- }, {});
32
- return cachedFilenameChunkIds;
33
- }
34
- export { getFilenameToChunkIdMap };
@@ -1,5 +0,0 @@
1
- import { StackFrame } from './types';
2
- export declare const MAX_CONTEXTLINES_COLNO: number;
3
- export declare const MAX_CONTEXTLINES_LINENO: number;
4
- export declare function addSourceContext(frames: StackFrame[]): Promise<StackFrame[]>;
5
- //# sourceMappingURL=context-lines.node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-lines.node.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/context-lines.node.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWpC,eAAO,MAAM,sBAAsB,EAAE,MAAa,CAAA;AAClD,eAAO,MAAM,uBAAuB,EAAE,MAAc,CAAA;AAIpD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAuElF"}
@@ -1,4 +0,0 @@
1
- import { ErrorProperties, EventHint, StackFrame, StackFrameModifierFn, StackParser } from './types';
2
- export declare function propertiesFromUnknownInput(stackParser: StackParser, frameModifiers: StackFrameModifierFn[], input: unknown, hint?: EventHint): Promise<ErrorProperties>;
3
- export declare function applyChunkIds(frames: StackFrame[], parser: StackParser): StackFrame[];
4
- //# sourceMappingURL=error-conversion.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-conversion.d.ts","sourceRoot":"","sources":["../../../src/extensions/error-tracking/error-conversion.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,eAAe,EACf,SAAS,EAGT,UAAU,EACV,oBAAoB,EACpB,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,oBAAoB,EAAE,EACtC,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,eAAe,CAAC,CAoB1B;AAiPD,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,WAAW,GAAG,UAAU,EAAE,CASrF"}
@@ -1,183 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- propertiesFromUnknownInput: ()=>propertiesFromUnknownInput,
28
- applyChunkIds: ()=>applyChunkIds
29
- });
30
- const external_chunk_ids_js_namespaceObject = require("./chunk-ids.js");
31
- const external_type_checking_js_namespaceObject = require("./type-checking.js");
32
- async function propertiesFromUnknownInput(stackParser, frameModifiers, input, hint) {
33
- const providedMechanism = hint && hint.mechanism;
34
- const mechanism = providedMechanism || {
35
- handled: true,
36
- type: 'generic'
37
- };
38
- const errorList = getErrorList(mechanism, input, hint);
39
- const exceptionList = await Promise.all(errorList.map(async (error)=>{
40
- const exception = await exceptionFromError(stackParser, frameModifiers, error);
41
- exception.value = exception.value || '';
42
- exception.type = exception.type || 'Error';
43
- exception.mechanism = mechanism;
44
- return exception;
45
- }));
46
- const properties = {
47
- $exception_list: exceptionList
48
- };
49
- return properties;
50
- }
51
- function getErrorList(mechanism, input, hint) {
52
- const error = getError(mechanism, input, hint);
53
- if (error.cause) return [
54
- error,
55
- ...getErrorList(mechanism, error.cause, hint)
56
- ];
57
- return [
58
- error
59
- ];
60
- }
61
- function getError(mechanism, exception, hint) {
62
- if ((0, external_type_checking_js_namespaceObject.isError)(exception)) return exception;
63
- mechanism.synthetic = true;
64
- if ((0, external_type_checking_js_namespaceObject.isPlainObject)(exception)) {
65
- const errorFromProp = getErrorPropertyFromObject(exception);
66
- if (errorFromProp) return errorFromProp;
67
- const message = getMessageForObject(exception);
68
- const ex = hint?.syntheticException || new Error(message);
69
- ex.message = message;
70
- return ex;
71
- }
72
- const ex = hint?.syntheticException || new Error(exception);
73
- ex.message = `${exception}`;
74
- return ex;
75
- }
76
- function getErrorPropertyFromObject(obj) {
77
- for(const prop in obj)if (Object.prototype.hasOwnProperty.call(obj, prop)) {
78
- const value = obj[prop];
79
- if ((0, external_type_checking_js_namespaceObject.isError)(value)) return value;
80
- }
81
- }
82
- function getMessageForObject(exception) {
83
- if ('name' in exception && 'string' == typeof exception.name) {
84
- let message = `'${exception.name}' captured as exception`;
85
- if ('message' in exception && 'string' == typeof exception.message) message += ` with message '${exception.message}'`;
86
- return message;
87
- }
88
- if ('message' in exception && 'string' == typeof exception.message) return exception.message;
89
- const keys = extractExceptionKeysForMessage(exception);
90
- if ((0, external_type_checking_js_namespaceObject.isErrorEvent)(exception)) return `Event \`ErrorEvent\` captured as exception with message \`${exception.message}\``;
91
- const className = getObjectClassName(exception);
92
- return `${className && 'Object' !== className ? `'${className}'` : 'Object'} captured as exception with keys: ${keys}`;
93
- }
94
- function getObjectClassName(obj) {
95
- try {
96
- const prototype = Object.getPrototypeOf(obj);
97
- return prototype ? prototype.constructor.name : void 0;
98
- } catch (e) {}
99
- }
100
- function extractExceptionKeysForMessage(exception, maxLength = 40) {
101
- const keys = Object.keys(convertToPlainObject(exception));
102
- keys.sort();
103
- const firstKey = keys[0];
104
- if (!firstKey) return '[object has no keys]';
105
- if (firstKey.length >= maxLength) return truncate(firstKey, maxLength);
106
- for(let includedKeys = keys.length; includedKeys > 0; includedKeys--){
107
- const serialized = keys.slice(0, includedKeys).join(', ');
108
- if (!(serialized.length > maxLength)) {
109
- if (includedKeys === keys.length) return serialized;
110
- return truncate(serialized, maxLength);
111
- }
112
- }
113
- return '';
114
- }
115
- function truncate(str, max = 0) {
116
- if ('string' != typeof str || 0 === max) return str;
117
- return str.length <= max ? str : `${str.slice(0, max)}...`;
118
- }
119
- function convertToPlainObject(value) {
120
- if ((0, external_type_checking_js_namespaceObject.isError)(value)) return {
121
- message: value.message,
122
- name: value.name,
123
- stack: value.stack,
124
- ...getOwnProperties(value)
125
- };
126
- if (!(0, external_type_checking_js_namespaceObject.isEvent)(value)) return value;
127
- {
128
- const newObj = {
129
- type: value.type,
130
- target: serializeEventTarget(value.target),
131
- currentTarget: serializeEventTarget(value.currentTarget),
132
- ...getOwnProperties(value)
133
- };
134
- return newObj;
135
- }
136
- }
137
- function getOwnProperties(obj) {
138
- if ('object' != typeof obj || null === obj) return {};
139
- {
140
- const extractedProps = {};
141
- for(const property in obj)if (Object.prototype.hasOwnProperty.call(obj, property)) extractedProps[property] = obj[property];
142
- return extractedProps;
143
- }
144
- }
145
- function serializeEventTarget(target) {
146
- try {
147
- return Object.prototype.toString.call(target);
148
- } catch (_oO) {
149
- return '<unknown>';
150
- }
151
- }
152
- async function exceptionFromError(stackParser, frameModifiers, error) {
153
- const exception = {
154
- type: error.name || error.constructor.name,
155
- value: error.message
156
- };
157
- let frames = parseStackFrames(stackParser, error);
158
- for (const modifier of frameModifiers)frames = await modifier(frames);
159
- if (frames.length) exception.stacktrace = {
160
- frames,
161
- type: 'raw'
162
- };
163
- return exception;
164
- }
165
- function parseStackFrames(stackParser, error) {
166
- return applyChunkIds(stackParser(error.stack || '', 1), stackParser);
167
- }
168
- function applyChunkIds(frames, parser) {
169
- const filenameChunkIdMap = (0, external_chunk_ids_js_namespaceObject.getFilenameToChunkIdMap)(parser);
170
- frames.forEach((frame)=>{
171
- if (frame.filename && filenameChunkIdMap) frame.chunk_id = filenameChunkIdMap[frame.filename];
172
- });
173
- return frames;
174
- }
175
- exports.applyChunkIds = __webpack_exports__.applyChunkIds;
176
- exports.propertiesFromUnknownInput = __webpack_exports__.propertiesFromUnknownInput;
177
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
178
- "applyChunkIds",
179
- "propertiesFromUnknownInput"
180
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
181
- Object.defineProperty(exports, '__esModule', {
182
- value: true
183
- });