Skip to content

Commit 4f8417e

Browse files
committed
fix: remove duplicate error handling; return potential non-number exit codes as 1
1 parent 6d51e2f commit 4f8417e

File tree

1 file changed

+17
-8
lines changed
  • packages/yarnpkg-cli/sources

1 file changed

+17
-8
lines changed

packages/yarnpkg-cli/sources/main.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import {pluginCommands}
1010
function runBinary(path: PortablePath) {
1111
const physicalPath = npath.fromPortablePath(path);
1212

13+
if (!physicalPath) {
14+
throw Object.assign(
15+
new Error(`runBinary ${path} ENOENT`),
16+
{code: `ENOENT`, errno: -2},
17+
);
18+
}
19+
1320
process.on(`SIGINT`, () => {
1421
// We don't want SIGINT to kill our process; we want it to kill the
1522
// innermost process, whose end will cause our own to exit.
@@ -99,14 +106,16 @@ export async function main({binaryVersion, pluginConfiguration}: {binaryVersion:
99106
await exec(cli);
100107
return;
101108
} else if (yarnPath !== null && !ignorePath) {
102-
if (!xfs.existsSync(yarnPath)) {
103-
process.stdout.write(cli.error(new Error(`The "yarn-path" option has been set (in ${configuration.sources.get(`yarnPath`)}), but the specified location doesn't exist (${yarnPath}).`)));
104-
process.exitCode = 1;
105-
} else {
106-
try {
107-
runBinary(yarnPath);
108-
} catch (error) {
109-
process.exitCode = error.code || 1;
109+
try {
110+
runBinary(yarnPath);
111+
} catch (error) {
112+
if (error.code === `ENOENT`)
113+
process.stdout.write(cli.error(new Error(`The "yarn-path" option has been set (in ${configuration.sources.get(`yarnPath`)}), but the specified location doesn't exist (${yarnPath}).`)));
114+
115+
if (typeof error.code === `number`) {
116+
process.exitCode = error.code;
117+
} else {
118+
process.exitCode = 1;
110119
}
111120
}
112121
} else {

0 commit comments

Comments
 (0)