Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exec): Handle node string error codes before setting process.exitCode #2031

Merged
merged 1 commit into from Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});