Skip to content

Commit 224bf49

Browse files
committed
imp(source-maps): do not send minified source cod frames
1 parent 0dacbde commit 224bf49

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/modules/stackParser.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,28 @@ export default class StackParser {
7070
const linesCollectCount = 5;
7171
const lineFrom = Math.max(0, actualLineNumber - linesCollectCount);
7272
const lineTo = Math.min(lines.length - 1, actualLineNumber + linesCollectCount + 1);
73-
const linesToCollect = lines.slice(lineFrom, lineTo);
74-
75-
return linesToCollect.map((content, index) => {
76-
return {
77-
line: lineFrom + index + 1,
78-
content,
79-
};
80-
});
73+
74+
const sourceCodeLines: SourceCodeLine[] = [];
75+
let extractedLineIndex = 1;
76+
77+
/**
78+
* In some cases column number of the error stack trace frame would be less then 200, but source code is minified
79+
* For this cases we need to check, that all of the lines to collect have length less than 200 too
80+
*/
81+
for (const lineToCheck in lines.slice(lineFrom, lineTo)) {
82+
if (lineToCheck.length > 200) {
83+
return null;
84+
} else {
85+
sourceCodeLines.push({
86+
line: lineFrom + extractedLineIndex,
87+
content: lineToCheck,
88+
});
89+
90+
extractedLineIndex += 1;
91+
}
92+
}
93+
94+
return sourceCodeLines;
8195
} catch (e) {
8296
console.warn('Hawk JS SDK: Can not extract source code. Please, report this issue: https://github.com/codex-team/hawk.javascript/issues/new', e);
8397

0 commit comments

Comments
 (0)