Skip to content

Commit

Permalink
Fix accidental truncation of multi-line error messages
Browse files Browse the repository at this point in the history
Fixes #1995.
  • Loading branch information
CrispusDH authored and novemberborn committed Jan 18, 2019
1 parent edfc005 commit 72e0762
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/serialize-error.js
Expand Up @@ -107,7 +107,16 @@ function trySerializeError(err, shouldBeautifyStack) {
} else {
// Skip the source line header inserted by `esm`:
// <https://github.com/standard-things/esm/wiki/improved-errors>
retval.summary = lines.find(line => !/:\d+$/.test(line));
const start = lines.findIndex(line => !/:\d+$/.test(line));
retval.summary = '';
for (let index = start; index < lines.length; index++) {
if (lines[index].startsWith(' at')) {
break;
}
const next = index + 1;
const end = next === lines.length || lines[next].startsWith(' at');
retval.summary += end ? lines[index] : lines[index] + '\n';
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/serialize-error.js
Expand Up @@ -180,10 +180,10 @@ test('creates multiline summaries for syntax errors', t => {
test('skips esm enhancement lines when finding the summary', t => {
const error = new Error();
Object.defineProperty(error, 'stack', {
value: 'file://file.js:1\nHello'
value: 'file://file.js:1\nFirst line\nSecond line'
});
const serializedError = serialize(error);
t.is(serializedError.summary, 'Hello');
t.is(serializedError.summary, 'First line\nSecond line');
t.end();
});

Expand Down

0 comments on commit 72e0762

Please sign in to comment.