From 224bf495cdbe1576e419bf3effb9b0e5f0a3f253 Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Sat, 8 Mar 2025 16:18:28 +0300 Subject: [PATCH 1/2] imp(source-maps): do not send minified source cod frames --- src/modules/stackParser.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/modules/stackParser.ts b/src/modules/stackParser.ts index 37dcc334..12abd836 100644 --- a/src/modules/stackParser.ts +++ b/src/modules/stackParser.ts @@ -70,14 +70,28 @@ export default class StackParser { const linesCollectCount = 5; const lineFrom = Math.max(0, actualLineNumber - linesCollectCount); const lineTo = Math.min(lines.length - 1, actualLineNumber + linesCollectCount + 1); - const linesToCollect = lines.slice(lineFrom, lineTo); - - return linesToCollect.map((content, index) => { - return { - line: lineFrom + index + 1, - content, - }; - }); + + const sourceCodeLines: SourceCodeLine[] = []; + let extractedLineIndex = 1; + + /** + * In some cases column number of the error stack trace frame would be less then 200, but source code is minified + * For this cases we need to check, that all of the lines to collect have length less than 200 too + */ + for (const lineToCheck in lines.slice(lineFrom, lineTo)) { + if (lineToCheck.length > 200) { + return null; + } else { + sourceCodeLines.push({ + line: lineFrom + extractedLineIndex, + content: lineToCheck, + }); + + extractedLineIndex += 1; + } + } + + return sourceCodeLines; } catch (e) { console.warn('Hawk JS SDK: Can not extract source code. Please, report this issue: https://github.com/codex-team/hawk.javascript/issues/new', e); From 27d928f510401b213cfa90ff7ac9e09533d74308 Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Sat, 8 Mar 2025 17:57:22 +0300 Subject: [PATCH 2/2] chore(stack-parser): add minifiedSourceCodeThreshold const --- src/modules/stackParser.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/stackParser.ts b/src/modules/stackParser.ts index 12abd836..4352288a 100644 --- a/src/modules/stackParser.ts +++ b/src/modules/stackParser.ts @@ -42,6 +42,8 @@ export default class StackParser { * @param {StackFrame} frame — information about backtrace item */ private async extractSourceCode(frame: StackFrame): Promise { + const minifiedSourceCodeThreshold = 200; + try { if (!frame.fileName) { return null; @@ -55,7 +57,7 @@ export default class StackParser { * If error occurred in large column number, the script probably minified * Skip minified bundles — they will be processed if user enabled source-maps tracking */ - if (frame.columnNumber && frame.columnNumber > 200) { + if (frame.columnNumber && frame.columnNumber > minifiedSourceCodeThreshold) { return null; } @@ -79,7 +81,7 @@ export default class StackParser { * For this cases we need to check, that all of the lines to collect have length less than 200 too */ for (const lineToCheck in lines.slice(lineFrom, lineTo)) { - if (lineToCheck.length > 200) { + if (lineToCheck.length > minifiedSourceCodeThreshold) { return null; } else { sourceCodeLines.push({