Skip to content

Commit

Permalink
fix(exec): Handle node string error codes before setting process.exit…
Browse files Browse the repository at this point in the history
…Code (#2031)
  • Loading branch information
KonstantinSimeonov authored and evocateur committed Apr 16, 2019
1 parent ff9c476 commit c599c64
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion commands/exec/index.js
@@ -1,5 +1,7 @@
"use strict";

const os = require("os");

const ChildProcessUtilities = require("@lerna/child-process");
const Command = require("@lerna/command");
const batchPackages = require("@lerna/batch-packages");
Expand Down Expand Up @@ -85,7 +87,18 @@ class ExecCommand extends Command {
/* istanbul ignore else */
if (results.some(result => result.failed)) {
// propagate "highest" error code, it's probably the most useful
const codes = results.filter(result => result.failed).map(result => result.code);
const codes = results
.filter(result => result.failed)
.map(result => {
switch (typeof result.code) {
case "number":
return result.code;
case "string":
return os.constants.errno[result.code];
default:
throw new TypeError("Received unexpected exit code value");
}
});
const exitCode = Math.max(...codes, 1);

this.logger.error("", "Received non-zero exit code %d during execution", exitCode);
Expand Down
13 changes: 13 additions & 0 deletions integration/lerna-exec.test.js
Expand Up @@ -175,4 +175,17 @@ success!

expect.hasAssertions();
});

test("string node error code is not swallowed", async () => {
const cwd = await initFixture("lerna-exec");
const args = ["exec", "--no-bail", "--concurrency=1", "--", "thing-that-is-missing"];

try {
await cliRunner(cwd)(...args);
} catch (err) {
expect(err.code).toBeGreaterThan(0);
}

expect.hasAssertions();
});
});

0 comments on commit c599c64

Please sign in to comment.