Skip to content

Commit 72e0762

Browse files
CrispusDHnovemberborn
authored andcommittedJan 18, 2019
Fix accidental truncation of multi-line error messages
Fixes #1995.
1 parent edfc005 commit 72e0762

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎lib/serialize-error.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ function trySerializeError(err, shouldBeautifyStack) {
107107
} else {
108108
// Skip the source line header inserted by `esm`:
109109
// <https://github.com/standard-things/esm/wiki/improved-errors>
110-
retval.summary = lines.find(line => !/:\d+$/.test(line));
110+
const start = lines.findIndex(line => !/:\d+$/.test(line));
111+
retval.summary = '';
112+
for (let index = start; index < lines.length; index++) {
113+
if (lines[index].startsWith(' at')) {
114+
break;
115+
}
116+
const next = index + 1;
117+
const end = next === lines.length || lines[next].startsWith(' at');
118+
retval.summary += end ? lines[index] : lines[index] + '\n';
119+
}
111120
}
112121
}
113122

‎test/serialize-error.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ test('creates multiline summaries for syntax errors', t => {
180180
test('skips esm enhancement lines when finding the summary', t => {
181181
const error = new Error();
182182
Object.defineProperty(error, 'stack', {
183-
value: 'file://file.js:1\nHello'
183+
value: 'file://file.js:1\nFirst line\nSecond line'
184184
});
185185
const serializedError = serialize(error);
186-
t.is(serializedError.summary, 'Hello');
186+
t.is(serializedError.summary, 'First line\nSecond line');
187187
t.end();
188188
});
189189

0 commit comments

Comments
 (0)
Please sign in to comment.