Skip to content

Commit 3bd18bb

Browse files
fix: respect the errorStack option in stats output
1 parent b0e0e4c commit 3bd18bb

File tree

7 files changed

+74
-2
lines changed

7 files changed

+74
-2
lines changed

.changeset/empty-wasps-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Respect the `stats.errorStack` option in stats output.

lib/stats/DefaultStatsFactoryPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ const EXTRACT_ERROR = {
507507
object.details = /** @type {WebpackError} */ (error).details;
508508
}
509509
},
510-
errorStack: (object, error) => {
511-
if (typeof error !== "string") {
510+
errorStack: (object, error, _context, { errorStack }) => {
511+
if (typeof error !== "string" && errorStack) {
512512
object.stack = error.stack;
513513
}
514514
},

test/__snapshots__/StatsTestCases.basictest.js.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,27 @@ chunk (runtime: a) a.js (a) X bytes [entry] [rendered]
11781178
webpack x.x.x compiled successfully in X ms"
11791179
`;
11801180

1181+
exports[`StatsTestCases should print correct stats for error-stack-disabled-error 1`] = `
1182+
"asset main.js X KiB [emitted] (name: main)
1183+
./index.js X bytes [built] [code generated]
1184+
1185+
ERROR in Test error with stack
1186+
1187+
webpack x.x.x compiled with 1 error in X ms"
1188+
`;
1189+
1190+
exports[`StatsTestCases should print correct stats for error-stack-enabled-error 1`] = `
1191+
"asset main.js X KiB [emitted] (name: main)
1192+
./index.js X bytes [built] [code generated]
1193+
1194+
ERROR in Test error with stack
1195+
Error: Test error with stack
1196+
at Test.js:1:1
1197+
at compile.js:2:2
1198+
1199+
webpack x.x.x compiled with 1 error in X ms"
1200+
`;
1201+
11811202
exports[`StatsTestCases should print correct stats for errors-space-error 1`] = `
11821203
"assets by status X bytes [cached] 1 asset
11831204
./loader.js!./index.js X bytes [built] [code generated] [2 errors]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty entry - errors are added via plugin
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
3+
const { WebpackError } = require("../../../");
4+
5+
/** @type {import("../../../").Configuration} */
6+
module.exports = {
7+
mode: "development",
8+
entry: "./index.js",
9+
stats: {
10+
errorStack: false
11+
},
12+
plugins: [
13+
(compiler) => {
14+
compiler.hooks.compilation.tap("Test", (compilation) => {
15+
const err = new WebpackError("Test error with stack");
16+
err.stack =
17+
"Error: Test error with stack\n at Test.js:1:1\n at compile.js:2:2";
18+
compilation.errors.push(err);
19+
});
20+
}
21+
]
22+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty entry - errors are added via plugin
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
3+
const { WebpackError } = require("../../../");
4+
5+
/** @type {import("../../../").Configuration} */
6+
module.exports = {
7+
mode: "development",
8+
entry: "./index.js",
9+
stats: {
10+
errorStack: true
11+
},
12+
plugins: [
13+
(compiler) => {
14+
compiler.hooks.compilation.tap("Test", (compilation) => {
15+
const err = new WebpackError("Test error with stack");
16+
err.stack =
17+
"Error: Test error with stack\n at Test.js:1:1\n at compile.js:2:2";
18+
compilation.errors.push(err);
19+
});
20+
}
21+
]
22+
};

0 commit comments

Comments
 (0)