Skip to content

Commit acd867e

Browse files
committed
fix parsing of certain format
1 parent 83d444c commit acd867e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,22 @@ const { file } = cli.flags;
4242
} else {
4343
str = await clipboardy.read();
4444
}
45-
const stack = stackTraceParser.parse(str);
46-
if (stack.length === 0) throw new Error('No stack found');
4745

48-
const header = str.split('\n').find(line => line.trim().length > 0);
46+
let [header, ...lines] = str.trim().split(/\r?\n/);
47+
48+
lines = lines.map((line) => {
49+
// stacktrace-parser doesn't seem to support stacktrace lines like this:
50+
// index-12345678.js:1:2 a
51+
const match = line.match(/^(\s+)([^\s]+:\d+:\d+)\s+([^\s]+)$/);
52+
if (match) {
53+
return `${match[1]}at ${match[3]} (${match[2]})`;
54+
}
55+
56+
return line;
57+
})
58+
59+
const stack = stackTraceParser.parse(lines.join('\n'));
60+
if (stack.length === 0) throw new Error('No stack found');
4961

5062
if (header) console.log(header);
5163

0 commit comments

Comments
 (0)