Skip to content

Commit eed1412

Browse files
committed
fix: log unhandled error even if its stack is empty
1 parent 5d63afa commit eed1412

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- `[jest-cli]` When specifying paths on the command line, only match against the relative paths of the test files ([#12519](https://github.com/facebook/jest/pull/12519))
3232
- [**BREAKING**] Changes `testPathPattern` configuration option to `testPathPatterns`, which now takes a list of patterns instead of the regex.
3333
- [**BREAKING**] `--testPathPattern` is now `--testPathPatterns`
34+
- `[jest-reporters, jest-runner]` Unhandled errors without stack get correctly logged to console ([#14619](https://github.com/facebook/jest/pull/14619))
3435

3536
### Performance
3637

packages/jest-reporters/src/CoverageWorker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export type CoverageWorkerData = {
3333

3434
// Make sure uncaught errors are logged before we exit.
3535
process.on('uncaughtException', err => {
36-
console.error(err.stack);
36+
if (err.stack) {
37+
console.error(err.stack);
38+
} else {
39+
console.error(err);
40+
}
3741
exit(1);
3842
});
3943

packages/jest-runner/src/testWorker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ type WorkerData = {
3535

3636
// Make sure uncaught errors are logged before we exit.
3737
process.on('uncaughtException', err => {
38-
console.error(err.stack);
38+
if (err.stack) {
39+
console.error(err.stack);
40+
} else {
41+
console.error(err);
42+
}
3943
exit(1);
4044
});
4145

0 commit comments

Comments
 (0)