@posthog/core 1.51.0 → 1.51.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.
package/LICENSE ADDED
@@ -0,0 +1,417 @@
1
+ Copyright 2020 Posthog / Hiberly, Inc.
2
+
3
+ Copyright 2015 Mixpanel, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this work except in compliance with the License.
7
+ You may obtain a copy of the License below, or at:
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ Apache License
18
+ Version 2.0, January 2004
19
+ http://www.apache.org/licenses/
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
193
+
194
+ APPENDIX: How to apply the Apache License to your work.
195
+
196
+ To apply the Apache License to your work, attach the following
197
+ boilerplate notice, with the fields enclosed by brackets "[]"
198
+ replaced with your own identifying information. (Don't include
199
+ the brackets!) The text should be enclosed in the appropriate
200
+ comment syntax for the file format. We also recommend that a
201
+ file or class name and description of purpose be included on the
202
+ same "printed page" as the copyright notice for easier
203
+ identification within third-party archives.
204
+
205
+ Copyright [yyyy] [name of copyright owner]
206
+
207
+ Licensed under the Apache License, Version 2.0 (the "License");
208
+ you may not use this file except in compliance with the License.
209
+ You may obtain a copy of the License at
210
+
211
+ http://www.apache.org/licenses/LICENSE-2.0
212
+
213
+ Unless required by applicable law or agreed to in writing, software
214
+ distributed under the License is distributed on an "AS IS" BASIS,
215
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
216
+ See the License for the specific language governing permissions and
217
+ limitations under the License.
218
+
219
+
220
+ ---
221
+
222
+ The @posthog/core package in packages/core is licensed under the MIT License below.
223
+ Third-party code remains subject to its respective notices in this file.
224
+ This owning notice is preserved from posthog-js-lite, from which @posthog/core was migrated:
225
+ https://github.com/PostHog/posthog-js-lite/blob/5fb7bee96f739b243dfea5589e2027f16629e8cd/LICENSE
226
+
227
+ MIT License
228
+
229
+ Copyright (c) 2022 PostHog (part of Hiberly Inc)
230
+
231
+ Permission is hereby granted, free of charge, to any person obtaining a copy
232
+ of this software and associated documentation files (the "Software"), to deal
233
+ in the Software without restriction, including without limitation the rights
234
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
235
+ copies of the Software, and to permit persons to whom the Software is
236
+ furnished to do so, subject to the following conditions:
237
+
238
+ The above copyright notice and this permission notice shall be included in all
239
+ copies or substantial portions of the Software.
240
+
241
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
242
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
243
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
244
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
245
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
246
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
247
+ SOFTWARE.
248
+
249
+ ---
250
+
251
+ packages/core/src/error-tracking/parsers/index.ts and its compiled distributions contain code
252
+ derived from TraceKit. This license only applies to the relevant code.
253
+
254
+ MIT License
255
+
256
+ Copyright (c) 2013 Onur Can Cakmak onur.cakmak@gmail.com and all TraceKit contributors.
257
+
258
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
259
+ software and associated documentation files(the 'Software'), to deal in the Software
260
+ without restriction, including without limitation the rights to use, copy, modify,
261
+ merge, publish, distribute, sublicense, and / or sell copies of the Software, and to
262
+ permit persons to whom the Software is furnished to do so, subject to the following
263
+ conditions:
264
+
265
+ The above copyright notice and this permission notice shall be included in all copies
266
+ or substantial portions of the Software.
267
+
268
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
269
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
270
+ PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
271
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
272
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
273
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
274
+
275
+ ---
276
+
277
+ packages/core/src/vendor/uuidv7.ts and its compiled distributions contain code from uuidv7:
278
+ https://github.com/LiosK/uuidv7/blob/f30b7a7faff73afbce0b27a46c638310f96912ba/src/index.ts
279
+
280
+ Copyright 2021-2023 LiosK
281
+
282
+ This code is licensed under the Apache License, Version 2.0, reproduced above.
283
+
284
+ ---
285
+
286
+ Some files in this codebase contain code from getsentry/sentry-javascript.
287
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
288
+
289
+ MIT License
290
+
291
+ Copyright (c) 2012 Functional Software, Inc. dba Sentry
292
+
293
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
294
+ this software and associated documentation files (the "Software"), to deal in
295
+ the Software without restriction, including without limitation the rights to
296
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
297
+ of the Software, and to permit persons to whom the Software is furnished to do
298
+ so, subject to the following conditions:
299
+
300
+ The above copyright notice and this permission notice shall be included in all
301
+ copies or substantial portions of the Software.
302
+
303
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
304
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
305
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
306
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
307
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
308
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
309
+ SOFTWARE.
310
+
311
+ ---
312
+
313
+ Some files in this codebase contain code from getsentry/sentry-react-native.
314
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
315
+
316
+ The MIT License (MIT)
317
+
318
+ Copyright (c) 2017 Sentry
319
+
320
+ Permission is hereby granted, free of charge, to any person obtaining a copy
321
+ of this software and associated documentation files (the "Software"), to deal
322
+ in the Software without restriction, including without limitation the rights
323
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
324
+ copies of the Software, and to permit persons to whom the Software is
325
+ furnished to do so, subject to the following conditions:
326
+
327
+ The above copyright notice and this permission notice shall be included in all
328
+ copies or substantial portions of the Software.
329
+
330
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
331
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
332
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
333
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
334
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
335
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
336
+ SOFTWARE.
337
+
338
+ ---
339
+
340
+ Some files in this codebase contain code from facebook/metro by Meta Platforms, Inc. and affiliates.
341
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
342
+
343
+ MIT License
344
+
345
+ Copyright (c) Meta Platforms, Inc. and affiliates.
346
+
347
+ Permission is hereby granted, free of charge, to any person obtaining a copy
348
+ of this software and associated documentation files (the "Software"), to deal
349
+ in the Software without restriction, including without limitation the rights
350
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
351
+ copies of the Software, and to permit persons to whom the Software is
352
+ furnished to do so, subject to the following conditions:
353
+
354
+ The above copyright notice and this permission notice shall be included in all
355
+ copies or substantial portions of the Software.
356
+
357
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
358
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
359
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
360
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
361
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
362
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
363
+ SOFTWARE.
364
+
365
+ ---
366
+
367
+ Some files in this codebase contain code from expo/expo by 650 Industries, Inc. (aka Expo).
368
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
369
+
370
+ The MIT License (MIT)
371
+
372
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
373
+
374
+ Permission is hereby granted, free of charge, to any person obtaining a copy
375
+ of this software and associated documentation files (the "Software"), to deal
376
+ in the Software without restriction, including without limitation the rights
377
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
378
+ copies of the Software, and to permit persons to whom the Software is
379
+ furnished to do so, subject to the following conditions:
380
+
381
+ The above copyright notice and this permission notice shall be included in all
382
+ copies or substantial portions of the Software.
383
+
384
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
385
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
386
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
387
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
388
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
389
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
390
+ SOFTWARE.
391
+
392
+ ---
393
+
394
+ Some files in this codebase contain code from agentcathq/agentcat-typescript-sdk (formerly MCPCat/mcpcat-typescript-sdk).
395
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
396
+
397
+ MIT License
398
+
399
+ Copyright (c) 2025 AgentCat, Inc. (formerly MCPcat)
400
+
401
+ Permission is hereby granted, free of charge, to any person obtaining a copy
402
+ of this software and associated documentation files (the "Software"), to deal
403
+ in the Software without restriction, including without limitation the rights
404
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
405
+ copies of the Software, and to permit persons to whom the Software is
406
+ furnished to do so, subject to the following conditions:
407
+
408
+ The above copyright notice and this permission notice shall be included in all
409
+ copies or substantial portions of the Software.
410
+
411
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
412
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
413
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
414
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
415
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
416
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
417
+ SOFTWARE.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/index.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAI7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAK5C,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,UAAU,EAAE,CAcpF;AAMD,wBAAgB,wBAAwB,IAAI,WAAW,CAEtD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,GAAG,WAAW,CAsChG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/index.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAI7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AA4J5C,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,UAAU,EAAE,CAcpF;AAMD,wBAAgB,wBAAwB,IAAI,WAAW,CAEtD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,GAAG,WAAW,CAkFhG"}
@@ -46,6 +46,69 @@ const external_opera_js_namespaceObject = require("./opera.js");
46
46
  const external_node_js_namespaceObject = require("./node.js");
47
47
  const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
48
48
  const STACKTRACE_FRAME_LIMIT = 50;
49
+ const MAX_REPEATED_CYCLE_LENGTH = 10;
50
+ const STACKTRACE_LINE_LIMIT = 1000;
51
+ function isSameFrame(a, b) {
52
+ return a.filename === b.filename && a.function === b.function && a.module === b.module && a.lineno === b.lineno && a.colno === b.colno;
53
+ }
54
+ function collapseRepeatedCycle(frames) {
55
+ for(let length = 1; length <= MAX_REPEATED_CYCLE_LENGTH; length++){
56
+ const start = frames.length - 2 * length;
57
+ if (start < 0) break;
58
+ let isCycle = true;
59
+ for(let offset = 0; offset < length; offset++){
60
+ const inner = frames[start + offset];
61
+ if (!isSameFrame(inner, frames[start + length + offset])) {
62
+ isCycle = false;
63
+ break;
64
+ }
65
+ }
66
+ if (isCycle) {
67
+ for(let offset = 0; offset < length; offset++)frames[start + offset] = frames[start + length + offset];
68
+ frames.length = start + length;
69
+ return {
70
+ start,
71
+ length
72
+ };
73
+ }
74
+ }
75
+ }
76
+ function trimPartialCycle(frames, cycle) {
77
+ const copyEnd = cycle.start + cycle.length;
78
+ const partialLength = partialCycleLength(frames, cycle);
79
+ if (partialLength) frames.splice(copyEnd + partialLength === frames.length ? copyEnd : cycle.start, partialLength);
80
+ }
81
+ function innermostPartialCycleLength(frames, cycle) {
82
+ let partialStart = cycle.start;
83
+ while(partialStart > 0 && isSameFrame(frames[partialStart - 1], frames[partialStart - 1 + cycle.length]))partialStart--;
84
+ return cycle.start - partialStart;
85
+ }
86
+ function partialCycleLength(frames, cycle) {
87
+ const copyEnd = cycle.start + cycle.length;
88
+ let partialEnd = copyEnd;
89
+ while(partialEnd < frames.length && isSameFrame(frames[partialEnd], frames[partialEnd - cycle.length]))partialEnd++;
90
+ return partialEnd - copyEnd;
91
+ }
92
+ function survivingFrameCount(frames, cycles) {
93
+ const innermostCycle = cycles[0];
94
+ let count = frames.length - (innermostCycle ? innermostPartialCycleLength(frames, innermostCycle) : 0);
95
+ for (const cycle of cycles)count -= partialCycleLength(frames, cycle);
96
+ return count;
97
+ }
98
+ function canonicalizeCycleRotation(frames) {
99
+ const keys = frames.map((frame)=>`${frame.function}|${frame.filename}|${frame.lineno}|${frame.colno}|${frame.module}`);
100
+ let first = 0;
101
+ for(let i = 1; i < keys.length; i++)if (isSmallerRotation(keys, i, first)) first = i;
102
+ frames.push(...frames.splice(0, first));
103
+ }
104
+ function isSmallerRotation(keys, candidate, best) {
105
+ for(let offset = 0; offset < keys.length; offset++){
106
+ const left = keys[(candidate + offset) % keys.length];
107
+ const right = keys[(best + offset) % keys.length];
108
+ if (left !== right) return left < right;
109
+ }
110
+ return false;
111
+ }
49
112
  function reverseAndStripFrames(stack) {
50
113
  if (!stack.length) return [];
51
114
  const localStack = Array.from(stack);
@@ -66,7 +129,9 @@ function createStackParser(platform, ...parsers) {
66
129
  return (stack, skipFirstLines = 0)=>{
67
130
  const frames = [];
68
131
  const lines = stack.split('\n');
69
- for(let i = skipFirstLines; i < lines.length; i++){
132
+ const endLine = Math.min(lines.length, skipFirstLines + STACKTRACE_LINE_LIMIT);
133
+ const repeatedCycles = [];
134
+ for(let i = skipFirstLines; i < endLine; i++){
70
135
  const line = lines[i];
71
136
  if (line.length > 1024) continue;
72
137
  const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, '$1') : line;
@@ -75,12 +140,32 @@ function createStackParser(platform, ...parsers) {
75
140
  const frame = parser(cleanedLine, platform);
76
141
  if (frame) {
77
142
  frames.push(frame);
143
+ const cycle = collapseRepeatedCycle(frames);
144
+ if (cycle) {
145
+ for(let i = repeatedCycles.length - 1; i >= 0; i--){
146
+ const previous = repeatedCycles[i];
147
+ if (previous.start + previous.length <= cycle.start) break;
148
+ repeatedCycles.pop();
149
+ }
150
+ repeatedCycles.push(cycle);
151
+ }
78
152
  break;
79
153
  }
80
154
  }
81
- if (frames.length >= STACKTRACE_FRAME_LIMIT) break;
155
+ if (survivingFrameCount(frames, repeatedCycles) >= STACKTRACE_FRAME_LIMIT) break;
82
156
  }
83
157
  }
158
+ const sections = [
159
+ ...repeatedCycles
160
+ ].sort((a, b)=>b.start - a.start);
161
+ const innermostSection = sections[sections.length - 1];
162
+ if (innermostSection) {
163
+ const trimmed = innermostPartialCycleLength(frames, innermostSection);
164
+ frames.splice(innermostSection.start - trimmed, trimmed);
165
+ for (const cycle of sections)cycle.start -= trimmed;
166
+ }
167
+ for (const cycle of sections)trimPartialCycle(frames, cycle);
168
+ if (repeatedCycles.some((cycle)=>0 === cycle.start && frames.length === cycle.length)) canonicalizeCycleRotation(frames);
84
169
  return reverseAndStripFrames(frames);
85
170
  };
86
171
  }
@@ -3,6 +3,69 @@ import { chromeStackLineParser } from "./chrome.mjs";
3
3
  import { geckoStackLineParser } from "./gecko.mjs";
4
4
  const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
5
5
  const STACKTRACE_FRAME_LIMIT = 50;
6
+ const MAX_REPEATED_CYCLE_LENGTH = 10;
7
+ const STACKTRACE_LINE_LIMIT = 1000;
8
+ function isSameFrame(a, b) {
9
+ return a.filename === b.filename && a.function === b.function && a.module === b.module && a.lineno === b.lineno && a.colno === b.colno;
10
+ }
11
+ function collapseRepeatedCycle(frames) {
12
+ for(let length = 1; length <= MAX_REPEATED_CYCLE_LENGTH; length++){
13
+ const start = frames.length - 2 * length;
14
+ if (start < 0) break;
15
+ let isCycle = true;
16
+ for(let offset = 0; offset < length; offset++){
17
+ const inner = frames[start + offset];
18
+ if (!isSameFrame(inner, frames[start + length + offset])) {
19
+ isCycle = false;
20
+ break;
21
+ }
22
+ }
23
+ if (isCycle) {
24
+ for(let offset = 0; offset < length; offset++)frames[start + offset] = frames[start + length + offset];
25
+ frames.length = start + length;
26
+ return {
27
+ start,
28
+ length
29
+ };
30
+ }
31
+ }
32
+ }
33
+ function trimPartialCycle(frames, cycle) {
34
+ const copyEnd = cycle.start + cycle.length;
35
+ const partialLength = partialCycleLength(frames, cycle);
36
+ if (partialLength) frames.splice(copyEnd + partialLength === frames.length ? copyEnd : cycle.start, partialLength);
37
+ }
38
+ function innermostPartialCycleLength(frames, cycle) {
39
+ let partialStart = cycle.start;
40
+ while(partialStart > 0 && isSameFrame(frames[partialStart - 1], frames[partialStart - 1 + cycle.length]))partialStart--;
41
+ return cycle.start - partialStart;
42
+ }
43
+ function partialCycleLength(frames, cycle) {
44
+ const copyEnd = cycle.start + cycle.length;
45
+ let partialEnd = copyEnd;
46
+ while(partialEnd < frames.length && isSameFrame(frames[partialEnd], frames[partialEnd - cycle.length]))partialEnd++;
47
+ return partialEnd - copyEnd;
48
+ }
49
+ function survivingFrameCount(frames, cycles) {
50
+ const innermostCycle = cycles[0];
51
+ let count = frames.length - (innermostCycle ? innermostPartialCycleLength(frames, innermostCycle) : 0);
52
+ for (const cycle of cycles)count -= partialCycleLength(frames, cycle);
53
+ return count;
54
+ }
55
+ function canonicalizeCycleRotation(frames) {
56
+ const keys = frames.map((frame)=>`${frame.function}|${frame.filename}|${frame.lineno}|${frame.colno}|${frame.module}`);
57
+ let first = 0;
58
+ for(let i = 1; i < keys.length; i++)if (isSmallerRotation(keys, i, first)) first = i;
59
+ frames.push(...frames.splice(0, first));
60
+ }
61
+ function isSmallerRotation(keys, candidate, best) {
62
+ for(let offset = 0; offset < keys.length; offset++){
63
+ const left = keys[(candidate + offset) % keys.length];
64
+ const right = keys[(best + offset) % keys.length];
65
+ if (left !== right) return left < right;
66
+ }
67
+ return false;
68
+ }
6
69
  function reverseAndStripFrames(stack) {
7
70
  if (!stack.length) return [];
8
71
  const localStack = Array.from(stack);
@@ -23,7 +86,9 @@ function createStackParser(platform, ...parsers) {
23
86
  return (stack, skipFirstLines = 0)=>{
24
87
  const frames = [];
25
88
  const lines = stack.split('\n');
26
- for(let i = skipFirstLines; i < lines.length; i++){
89
+ const endLine = Math.min(lines.length, skipFirstLines + STACKTRACE_LINE_LIMIT);
90
+ const repeatedCycles = [];
91
+ for(let i = skipFirstLines; i < endLine; i++){
27
92
  const line = lines[i];
28
93
  if (line.length > 1024) continue;
29
94
  const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, '$1') : line;
@@ -32,12 +97,32 @@ function createStackParser(platform, ...parsers) {
32
97
  const frame = parser(cleanedLine, platform);
33
98
  if (frame) {
34
99
  frames.push(frame);
100
+ const cycle = collapseRepeatedCycle(frames);
101
+ if (cycle) {
102
+ for(let i = repeatedCycles.length - 1; i >= 0; i--){
103
+ const previous = repeatedCycles[i];
104
+ if (previous.start + previous.length <= cycle.start) break;
105
+ repeatedCycles.pop();
106
+ }
107
+ repeatedCycles.push(cycle);
108
+ }
35
109
  break;
36
110
  }
37
111
  }
38
- if (frames.length >= STACKTRACE_FRAME_LIMIT) break;
112
+ if (survivingFrameCount(frames, repeatedCycles) >= STACKTRACE_FRAME_LIMIT) break;
39
113
  }
40
114
  }
115
+ const sections = [
116
+ ...repeatedCycles
117
+ ].sort((a, b)=>b.start - a.start);
118
+ const innermostSection = sections[sections.length - 1];
119
+ if (innermostSection) {
120
+ const trimmed = innermostPartialCycleLength(frames, innermostSection);
121
+ frames.splice(innermostSection.start - trimmed, trimmed);
122
+ for (const cycle of sections)cycle.start -= trimmed;
123
+ }
124
+ for (const cycle of sections)trimPartialCycle(frames, cycle);
125
+ if (repeatedCycles.some((cycle)=>0 === cycle.start && frames.length === cycle.length)) canonicalizeCycleRotation(frames);
41
126
  return reverseAndStripFrames(frames);
42
127
  };
43
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/core",
3
- "version": "1.51.0",
3
+ "version": "1.51.2",
4
4
  "bugs": {
5
5
  "url": "https://github.com/PostHog/posthog-js/issues"
6
6
  },
@@ -70,7 +70,7 @@
70
70
  }
71
71
  },
72
72
  "dependencies": {
73
- "@posthog/types": "^1.409.1"
73
+ "@posthog/types": "^1.409.2"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@rslib/core": "0.23.2",
@@ -29,7 +29,9 @@ describe('ErrorPropertiesBuilder', () => {
29
29
  const syntheticError = new Error()
30
30
  const frames = parseStack(syntheticError)
31
31
  expect(frames).toBeDefined()
32
- expect(frames).toHaveLength(15)
32
+ // The test runner calls itself once per nested describe block, and the parser keeps one copy
33
+ // of a repeated frame cycle, so those repeats count as a single frame here.
34
+ expect(frames).toHaveLength(13)
33
35
  })
34
36
  })
35
37
  })
@@ -0,0 +1,270 @@
1
+ import { createDefaultStackParser } from './index'
2
+
3
+ describe('createDefaultStackParser repeated cycle collapsing', () => {
4
+ const parse = createDefaultStackParser()
5
+
6
+ const OVERFLOW = 'RangeError: Maximum call stack size exceeded'
7
+
8
+ const frame = (func: string, line: number, column: number = 10): string =>
9
+ ` at ${func} (https://posthog.com/app.js:${line}:${column})`
10
+
11
+ function recursion(cycle: string[], repeats: number): string[] {
12
+ const frames: string[] = []
13
+
14
+ for (let i = 0; i < repeats; i++) {
15
+ cycle.forEach((func, index) => frames.push(frame(func, index + 1)))
16
+ }
17
+
18
+ return frames
19
+ }
20
+
21
+ // The runtime lists the innermost frame first and cuts the stack wherever the depth ran out, so
22
+ // `dropInnermost` is how many frames of the cycle that cut took off the innermost end.
23
+ function overflowStack(cycle: string[], repeats: number, dropInnermost: number = 0): string {
24
+ return [
25
+ OVERFLOW,
26
+ ...recursion(cycle, repeats).slice(dropInnermost),
27
+ frame('handleClick', 90),
28
+ frame('main', 91),
29
+ ].join('\n')
30
+ }
31
+
32
+ function names(stack: string): (string | undefined)[] {
33
+ return parse(stack).map((f) => f.function)
34
+ }
35
+
36
+ it('keeps one copy of a recursion cycle', () => {
37
+ expect(names(overflowStack(['a', 'b'], 30))).toEqual(['main', 'handleClick', 'b', 'a'])
38
+ })
39
+
40
+ it('keeps one copy when a single function calls itself', () => {
41
+ expect(names(overflowStack(['a'], 60))).toEqual(['main', 'handleClick', 'a'])
42
+ })
43
+
44
+ it('keeps the outer frames a recursion used to push past the frame limit', () => {
45
+ // Without collapsing, the frame limit is spent on the cycle and the frames that name the
46
+ // caller never reach the event.
47
+ const frames = names(overflowStack(['a', 'b'], 400))
48
+ expect(frames).toContain('main')
49
+ expect(frames).toContain('handleClick')
50
+ })
51
+
52
+ it('gives the same frames wherever the runtime cut the recursion', () => {
53
+ // The overflow can happen in either function of the pair, which used to change the frames and
54
+ // so open a new issue for every throw.
55
+ const pair = names(overflowStack(['a', 'b'], 30))
56
+ expect(names(overflowStack(['a', 'b'], 30, 1))).toEqual(pair)
57
+
58
+ const triple = names(overflowStack(['a', 'b', 'c'], 30))
59
+ expect(names(overflowStack(['a', 'b', 'c'], 30, 1))).toEqual(triple)
60
+ expect(names(overflowStack(['a', 'b', 'c'], 30, 2))).toEqual(triple)
61
+ })
62
+
63
+ it('gives the same frames when the runtime cut everything outside the recursion', () => {
64
+ // The runtime keeps the innermost frames, so a deep recursion can push every other frame out of
65
+ // the stack. Nothing then says which function of the cycle ran out of stack first.
66
+ const recursionOnly = (dropInnermost: number): (string | undefined)[] =>
67
+ names([OVERFLOW, ...recursion(['a', 'b'], 40).slice(dropInnermost)].join('\n'))
68
+
69
+ expect(recursionOnly(1)).toEqual(recursionOnly(0))
70
+ })
71
+
72
+ it('gives the same frames when the stack holds a second repeated section', () => {
73
+ // Stacks repeat outside the recursion too, such as a test runner that calls itself once per
74
+ // nested block. The frames of that section have to keep the recursion's own partial copy.
75
+ const withOuterRepeat = (dropInnermost: number): (string | undefined)[] =>
76
+ names(
77
+ [
78
+ OVERFLOW,
79
+ ...recursion(['a', 'b'], 30).slice(dropInnermost),
80
+ frame('handleClick', 90),
81
+ frame('walk', 91),
82
+ frame('walk', 91),
83
+ frame('main', 92),
84
+ ].join('\n')
85
+ )
86
+
87
+ expect(withOuterRepeat(0)).toEqual(['main', 'walk', 'handleClick', 'b', 'a'])
88
+ expect(withOuterRepeat(1)).toEqual(withOuterRepeat(0))
89
+ })
90
+
91
+ it('gives the same frames when a cycle that repeats a call site is all that is left', () => {
92
+ // One copy of a cycle can hold the same call site twice, and the innermost frame carries a
93
+ // column of its own, so a single frame does not say which rotation of the copy this throw is.
94
+ const cycle = [frame('a', 1, 10), frame('b', 2), frame('a', 1, 20), frame('c', 4)]
95
+ const lines: string[] = []
96
+
97
+ for (let i = 0; i < 30; i++) {
98
+ lines.push(...cycle)
99
+ }
100
+
101
+ const fromCut = (dropInnermost: number): (string | undefined)[] =>
102
+ names([OVERFLOW, ...lines.slice(dropInnermost)].join('\n'))
103
+
104
+ expect(fromCut(0)).toEqual(['c', 'a', 'b', 'a'])
105
+ expect(fromCut(1)).toEqual(fromCut(0))
106
+ expect(fromCut(2)).toEqual(fromCut(0))
107
+ expect(fromCut(3)).toEqual(fromCut(0))
108
+ })
109
+
110
+ it('reads the outer frames a leftover copy would have pushed past the frame limit', () => {
111
+ // The leftover copy is dropped once the whole stack is read, so it must not hold a slot of the
112
+ // frame limit while the parser is still reading the frames outside the recursion.
113
+ const callers: string[] = []
114
+
115
+ for (let i = 0; i < 48; i++) {
116
+ callers.push(frame(`c${i}`, i + 10))
117
+ }
118
+
119
+ const withCallers = (dropInnermost: number): (string | undefined)[] =>
120
+ names([OVERFLOW, ...recursion(['a', 'b'], 30).slice(dropInnermost), ...callers].join('\n'))
121
+
122
+ expect(withCallers(0)).toHaveLength(50)
123
+ expect(withCallers(1)).toEqual(withCallers(0))
124
+
125
+ // A distinct throw location is not a partial copy and must use a slot of the frame budget.
126
+ const withThrowColumn = [OVERFLOW, frame('a', 1, 4), ...recursion(['a', 'b'], 30).slice(1), ...callers].join('\n')
127
+ const frames = parse(withThrowColumn)
128
+ expect(frames).toHaveLength(50)
129
+ expect(frames.map((f) => f.function)).toEqual([...withCallers(0).slice(1), 'a'])
130
+ expect(frames[frames.length - 1]?.colno).toBe(4)
131
+ })
132
+
133
+ it('gives the same frames when the recursion path calls one function twice in a row', () => {
134
+ // A minified bundle holds one line number per function, so the two calls to `b` are told apart
135
+ // by their column alone. The kept copy holds both of them, and every cut agrees on it.
136
+ const cycle = [frame('a', 1), frame('b', 2, 10), frame('b', 2, 20)]
137
+ const lines: string[] = []
138
+
139
+ for (let i = 0; i < 30; i++) {
140
+ lines.push(...cycle)
141
+ }
142
+
143
+ const fromCut = (dropInnermost: number): (string | undefined)[] =>
144
+ names([OVERFLOW, ...lines.slice(dropInnermost), frame('handleClick', 90), frame('main', 91)].join('\n'))
145
+
146
+ expect(fromCut(0)).toEqual(['main', 'handleClick', 'b', 'b', 'a'])
147
+ expect(fromCut(1)).toEqual(fromCut(0))
148
+ expect(fromCut(2)).toEqual(fromCut(0))
149
+ })
150
+
151
+ it('keeps minified frames that share a name and a line but not a column', () => {
152
+ // A minified bundle puts every function on one line and hands out the same short names, so the
153
+ // column is all that tells two of them apart. Nothing repeats here, so no frame may be dropped.
154
+ const stack = [
155
+ 'Error: boom',
156
+ frame('i', 1, 310),
157
+ frame('t', 1, 4821),
158
+ frame('t', 1, 9137),
159
+ frame('r', 1, 2210),
160
+ frame('onClick', 1, 640),
161
+ ].join('\n')
162
+
163
+ expect(parse(stack).map((f) => `${f.function}:${f.colno}`)).toEqual([
164
+ 'onClick:640',
165
+ 'r:2210',
166
+ 't:9137',
167
+ 't:4821',
168
+ 'i:310',
169
+ ])
170
+ })
171
+
172
+ it.each(['Error: boom', OVERFLOW])('preserves the unnamed throw location for %s', (header) => {
173
+ // Even a confirmed recursion cannot establish that a different innermost column is redundant.
174
+ // Keep that location for both ordinary errors and overflow stacks.
175
+ const anonymous = (column: number): string => ` at https://posthog.com/app.js:1:${column}`
176
+
177
+ const withThrowColumn = (column: number): string[] => {
178
+ const lines = [anonymous(column)]
179
+
180
+ for (let i = 1; i < 40; i++) {
181
+ lines.push(anonymous(10))
182
+ }
183
+
184
+ return parse([header, ...lines, frame('handleClick', 90), frame('main', 91)].join('\n')).map(
185
+ (f) => `${f.function}:${f.colno}`
186
+ )
187
+ }
188
+
189
+ expect(withThrowColumn(4)).toEqual(['main:10', 'handleClick:10', '?:10', '?:4'])
190
+ expect(withThrowColumn(5)).toEqual(['main:10', 'handleClick:10', '?:10', '?:5'])
191
+ expect(withThrowColumn(10)).toEqual(['main:10', 'handleClick:10', '?:10'])
192
+ })
193
+
194
+ it('preserves the column of the call that ran out of stack', () => {
195
+ // Do not guess whether a different column is a redundant overflow location or a distinct throw.
196
+ const stack = [OVERFLOW, frame('a', 1, 4), ...recursion(['a', 'b'], 3).slice(1), frame('handleClick', 90)].join(
197
+ '\n'
198
+ )
199
+
200
+ expect(parse(stack).map((f) => `${f.function}:${f.colno}`)).toEqual(['handleClick:10', 'b:10', 'a:10', 'a:4'])
201
+ })
202
+
203
+ it('keeps frames that repeat without a complete second cycle', () => {
204
+ const stack = ['Error: boom', frame('a', 1), frame('b', 2), frame('a', 1), frame('main', 91)].join('\n')
205
+ expect(names(stack)).toEqual(['main', 'a', 'b', 'a'])
206
+ })
207
+
208
+ it('invalidates a cycle record subsumed by a later collapse', () => {
209
+ const stack = ['Error: boom', frame('a', 1), frame('b', 2), frame('a', 1), frame('a', 1), frame('b', 2)].join('\n')
210
+
211
+ expect(names(stack)).toEqual(['b', 'a'])
212
+ })
213
+
214
+ it('keeps disjoint cycle records when a later collapse subsumes another record', () => {
215
+ const stack = [
216
+ 'Error: boom',
217
+ frame('inner', 90),
218
+ frame('inner', 90),
219
+ frame('a', 1),
220
+ frame('b', 2),
221
+ frame('a', 1),
222
+ frame('a', 1),
223
+ frame('b', 2),
224
+ frame('outer', 91),
225
+ frame('outer', 91),
226
+ ].join('\n')
227
+
228
+ expect(names(stack)).toEqual(['outer', 'b', 'a', 'inner'])
229
+ })
230
+
231
+ it.each([4, 5])('preserves the throw column %i of an ordinary recursive error', (column) => {
232
+ const stack = [
233
+ 'Error: boom',
234
+ frame('recurse', 1, column),
235
+ frame('recurse', 1, 10),
236
+ frame('recurse', 1, 10),
237
+ frame('main', 91),
238
+ ].join('\n')
239
+
240
+ expect(parse(stack).map((f) => `${f.function}:${f.colno}`)).toEqual(['main:10', 'recurse:10', `recurse:${column}`])
241
+ })
242
+
243
+ it('keeps distinct innermost minified call sites for an ordinary error', () => {
244
+ const stack = ['Error: boom', frame('t', 1, 100), frame('t', 1, 200), frame('main', 91)].join('\n')
245
+
246
+ expect(parse(stack).map((f) => `${f.function}:${f.colno}`)).toEqual(['main:10', 't:200', 't:100'])
247
+ })
248
+
249
+ it('canonicalizes recursion-only cycles whose rotations differ only by columns', () => {
250
+ const cycle = [frame('a', 1, 10), frame('b', 1, 20), frame('a', 1, 30), frame('b', 1, 40)]
251
+ const lines: string[] = []
252
+
253
+ for (let i = 0; i < 30; i++) {
254
+ lines.push(...cycle)
255
+ }
256
+
257
+ const fromCut = (dropInnermost: number): string[] =>
258
+ parse([OVERFLOW, ...lines.slice(dropInnermost)].join('\n')).map((f) => `${f.function}:${f.colno}`)
259
+
260
+ expect(fromCut(0)).toEqual(['b:40', 'a:30', 'b:20', 'a:10'])
261
+ expect(fromCut(1)).toEqual(fromCut(0))
262
+ expect(fromCut(2)).toEqual(fromCut(0))
263
+ expect(fromCut(3)).toEqual(fromCut(0))
264
+ })
265
+
266
+ it('keeps calls to one function from different call sites', () => {
267
+ const stack = ['Error: boom', frame('a', 1), frame('a', 2), frame('a', 3), frame('main', 91)].join('\n')
268
+ expect(names(stack)).toEqual(['main', 'a', 'a', 'a'])
269
+ })
270
+ })
@@ -42,6 +42,157 @@ export { nodeStackLineParser } from './node'
42
42
  const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/
43
43
  const STACKTRACE_FRAME_LIMIT = 50
44
44
 
45
+ // A recursion spends the whole frame limit on one repeating cycle, so the frames that name the real
46
+ // culprit sit past the limit, and where the runtime cut the stack decides which frames are left.
47
+ // One fault can then open multiple error tracking issues. The parser keeps a single copy of an exact
48
+ // cycle instead, making room for outer frames and reducing depth-dependent differences without
49
+ // discarding distinct throw locations. Longer cycles are rare and cost an extra comparison pass.
50
+ const MAX_REPEATED_CYCLE_LENGTH = 10
51
+ // How many lines to read, now that a recursion no longer stops the parser at the frame limit.
52
+ const STACKTRACE_LINE_LIMIT = 1000
53
+
54
+ // A minified bundle puts many functions on one line and gives them the same short names, so the
55
+ // column is what tells two of them apart. Even a confirmed cycle must preserve a distinct throw
56
+ // location: the frame list alone cannot distinguish an overflow from an ordinary recursive error.
57
+ function isSameFrame(a: StackFrame, b: StackFrame): boolean {
58
+ return (
59
+ a.filename === b.filename &&
60
+ a.function === b.function &&
61
+ a.module === b.module &&
62
+ a.lineno === b.lineno &&
63
+ a.colno === b.colno
64
+ )
65
+ }
66
+
67
+ interface RepeatedCycle {
68
+ start: number
69
+ length: number
70
+ }
71
+
72
+ // Removes the cycle that ends at the last frame when the frames before it are the same cycle, and
73
+ // reports where the copy that was kept sits. This runs after every frame is added, so a recursion
74
+ // never grows past one copy of its cycle.
75
+ function collapseRepeatedCycle(frames: StackFrame[]): RepeatedCycle | undefined {
76
+ for (let length = 1; length <= MAX_REPEATED_CYCLE_LENGTH; length++) {
77
+ const start = frames.length - 2 * length
78
+ if (start < 0) {
79
+ return undefined
80
+ }
81
+
82
+ let isCycle = true
83
+ for (let offset = 0; offset < length; offset++) {
84
+ const inner = frames[start + offset] as StackFrame
85
+
86
+ if (!isSameFrame(inner, frames[start + length + offset] as StackFrame)) {
87
+ isCycle = false
88
+ break
89
+ }
90
+ }
91
+
92
+ if (isCycle) {
93
+ // Keep the outer copy of the matching frames.
94
+ for (let offset = 0; offset < length; offset++) {
95
+ frames[start + offset] = frames[start + length + offset] as StackFrame
96
+ }
97
+
98
+ frames.length = start + length
99
+ return { start, length }
100
+ }
101
+ }
102
+
103
+ return undefined
104
+ }
105
+
106
+ // The stack is cut wherever the depth ran out, so a part of the cycle can be left over next to the
107
+ // copy that was kept. That leftover part is what moved the fingerprint from one throw to the next.
108
+ // Remove it at the end the stack was cut at, so that the frame the code outside the cycle really
109
+ // called stays next to it.
110
+ function trimPartialCycle(frames: StackFrame[], cycle: RepeatedCycle): void {
111
+ const copyEnd = cycle.start + cycle.length
112
+ const partialLength = partialCycleLength(frames, cycle)
113
+
114
+ if (partialLength) {
115
+ frames.splice(copyEnd + partialLength === frames.length ? copyEnd : cycle.start, partialLength)
116
+ }
117
+ }
118
+
119
+ // Counts an exact partial copy left over at the innermost end.
120
+ function innermostPartialCycleLength(frames: StackFrame[], cycle: RepeatedCycle): number {
121
+ let partialStart = cycle.start
122
+
123
+ while (
124
+ partialStart > 0 &&
125
+ isSameFrame(frames[partialStart - 1] as StackFrame, frames[partialStart - 1 + cycle.length] as StackFrame)
126
+ ) {
127
+ partialStart--
128
+ }
129
+
130
+ return cycle.start - partialStart
131
+ }
132
+
133
+ // How much of the cycle is left over next to the copy that was kept.
134
+ function partialCycleLength(frames: StackFrame[], cycle: RepeatedCycle): number {
135
+ const copyEnd = cycle.start + cycle.length
136
+ let partialEnd = copyEnd
137
+
138
+ while (
139
+ partialEnd < frames.length &&
140
+ isSameFrame(frames[partialEnd] as StackFrame, frames[partialEnd - cycle.length] as StackFrame)
141
+ ) {
142
+ partialEnd++
143
+ }
144
+
145
+ return partialEnd - copyEnd
146
+ }
147
+
148
+ // The leftover copies are dropped once the whole stack is read, so the frame limit counts the
149
+ // frames that survive that. A leftover copy otherwise holds a slot while the loop runs, the parser
150
+ // stops before the outermost frames, and how many of them are read moves with where the stack was
151
+ // cut.
152
+ function survivingFrameCount(frames: StackFrame[], cycles: RepeatedCycle[]): number {
153
+ const innermostCycle = cycles[0]
154
+ let count = frames.length - (innermostCycle ? innermostPartialCycleLength(frames, innermostCycle) : 0)
155
+
156
+ for (const cycle of cycles) {
157
+ count -= partialCycleLength(frames, cycle)
158
+ }
159
+
160
+ return count
161
+ }
162
+
163
+ // When the runtime cut every frame outside the cycle, the trace is one copy of the cycle and
164
+ // nothing says which function of it ran out of stack first. Any rotation of the copy holds the same
165
+ // calls, so always keep the same one, and the fingerprint stays equal from one throw to the next.
166
+ function canonicalizeCycleRotation(frames: StackFrame[]): void {
167
+ const keys = frames.map(
168
+ (frame) => `${frame.function}|${frame.filename}|${frame.lineno}|${frame.colno}|${frame.module}`
169
+ )
170
+ let first = 0
171
+
172
+ for (let i = 1; i < keys.length; i++) {
173
+ if (isSmallerRotation(keys, i, first)) {
174
+ first = i
175
+ }
176
+ }
177
+
178
+ frames.push(...frames.splice(0, first))
179
+ }
180
+
181
+ // One copy of a cycle can hold the same call site more than once, so the smallest single frame does
182
+ // not name one rotation. Read both rotations from their first frame on, and the whole copy decides.
183
+ function isSmallerRotation(keys: string[], candidate: number, best: number): boolean {
184
+ for (let offset = 0; offset < keys.length; offset++) {
185
+ const left = keys[(candidate + offset) % keys.length] as string
186
+ const right = keys[(best + offset) % keys.length] as string
187
+
188
+ if (left !== right) {
189
+ return left < right
190
+ }
191
+ }
192
+
193
+ return false
194
+ }
195
+
45
196
  export function reverseAndStripFrames(stack: ReadonlyArray<StackFrame>): StackFrame[] {
46
197
  if (!stack.length) {
47
198
  return []
@@ -71,7 +222,13 @@ export function createStackParser(platform: Platform, ...parsers: StackLineParse
71
222
  const frames: StackFrame[] = []
72
223
  const lines = stack.split('\n')
73
224
 
74
- for (let i = skipFirstLines; i < lines.length; i++) {
225
+ const endLine = Math.min(lines.length, skipFirstLines + STACKTRACE_LINE_LIMIT)
226
+ // A stack can hold more than one repeated section, such as a recursion under a test runner that
227
+ // calls itself once per nested block. Keep every section, because each of them can be left with
228
+ // a partial copy, and one section must not take the place of another.
229
+ const repeatedCycles: RepeatedCycle[] = []
230
+
231
+ for (let i = skipFirstLines; i < endLine; i++) {
75
232
  const line = lines[i] as string
76
233
  // Ignore lines over 1kb as they are unlikely to be stack frames.
77
234
  // Many of the regular expressions use backtracking which results in run time that increases exponentially with
@@ -93,15 +250,53 @@ export function createStackParser(platform: Platform, ...parsers: StackLineParse
93
250
  const frame = parser(cleanedLine, platform)
94
251
  if (frame) {
95
252
  frames.push(frame)
253
+ const cycle = collapseRepeatedCycle(frames)
254
+ if (cycle) {
255
+ // A collapse replaces the suffix starting at cycle.start. Discard records that overlap
256
+ // that suffix, including a previous copy of this cycle, before counting or trimming.
257
+ // The remaining records stay ordered and refer only to untouched earlier frames.
258
+ for (let i = repeatedCycles.length - 1; i >= 0; i--) {
259
+ const previous = repeatedCycles[i] as RepeatedCycle
260
+ if (previous.start + previous.length <= cycle.start) {
261
+ break
262
+ }
263
+ repeatedCycles.pop()
264
+ }
265
+ repeatedCycles.push(cycle)
266
+ }
96
267
  break
97
268
  }
98
269
  }
99
270
 
100
- if (frames.length >= STACKTRACE_FRAME_LIMIT) {
271
+ if (survivingFrameCount(frames, repeatedCycles) >= STACKTRACE_FRAME_LIMIT) {
101
272
  break
102
273
  }
103
274
  }
104
275
 
276
+ // Trimming a section moves the frames after it, so work from the section furthest from the
277
+ // innermost frame and the positions recorded for the sections under it still hold.
278
+ const sections = [...repeatedCycles].sort((a, b) => b.start - a.start)
279
+ const innermostSection = sections[sections.length - 1]
280
+
281
+ // The innermost end goes first. Trimming a section rotates the copy it keeps, and the leftover
282
+ // only reads as part of the cycle while that copy still sits where the stack put it.
283
+ if (innermostSection) {
284
+ const trimmed = innermostPartialCycleLength(frames, innermostSection)
285
+ frames.splice(innermostSection.start - trimmed, trimmed)
286
+
287
+ for (const cycle of sections) {
288
+ cycle.start -= trimmed
289
+ }
290
+ }
291
+
292
+ for (const cycle of sections) {
293
+ trimPartialCycle(frames, cycle)
294
+ }
295
+
296
+ if (repeatedCycles.some((cycle) => cycle.start === 0 && frames.length === cycle.length)) {
297
+ canonicalizeCycleRotation(frames)
298
+ }
299
+
105
300
  return reverseAndStripFrames(frames)
106
301
  }
107
302
  }