Skip to content

Commit 2bcc366

Browse files
mnuttevocateur
authored andcommittedDec 27, 2018
fix: Do not print duplicate stdio after a streaming command errors (#1832)
Fixes #1790
1 parent ef18236 commit 2bcc366

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed
 

‎core/command/__tests__/command.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,33 @@ describe("core-command", () => {
198198
});
199199
}
200200
});
201+
202+
it("does not log stdout/stderr after streaming ends", async () => {
203+
class PkgErrorCommand extends Command {
204+
initialize() {
205+
return true;
206+
}
207+
208+
execute() {
209+
const err = new Error("message");
210+
211+
err.cmd = "test-pkg-err";
212+
err.stdout = "pkg-err-stdout";
213+
err.stderr = "pkg-err-stderr";
214+
err.pkg = {
215+
name: "pkg-err-name",
216+
};
217+
218+
throw err;
219+
}
220+
}
221+
222+
try {
223+
await new PkgErrorCommand({ cwd: testDir, stream: true });
224+
} catch (err) {
225+
expect(console.error.mock.calls).toHaveLength(0);
226+
}
227+
});
201228
});
202229

203230
describe("loglevel", () => {

‎core/command/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Command {
5959
err => {
6060
if (err.pkg) {
6161
// Cleanly log specific package error details
62-
logPackageError(err);
62+
logPackageError(err, this.options.stream);
6363
} else if (err.name !== "ValidationError") {
6464
// npmlog does some funny stuff to the stack by default,
6565
// so pass it directly to avoid duplication.

‎core/command/lib/log-package-error.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ const log = require("libnpm/log");
44

55
module.exports = logPackageError;
66

7-
function logPackageError(err) {
7+
function logPackageError(err, stream = false) {
88
log.error(err.cmd, `exited ${err.code} in '${err.pkg.name}'`);
99

10+
if (stream) {
11+
// Streaming has already printed all stdout/stderr
12+
return;
13+
}
14+
1015
if (err.stdout) {
1116
log.error(err.cmd, "stdout:");
1217
directLog(err.stdout);

0 commit comments

Comments
 (0)
Please sign in to comment.