From d73bf9c3a084b6a613b3ba47ee816544bcb6b042 Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Sat, 14 Sep 2024 18:12:11 -0400 Subject: [PATCH] fix(cli): handle consecutive npx install race condition (#4643) --- packages/cli/cli/src/rerunFernCliAtVersion.ts | 9 ++++++++- packages/cli/cli/versions.yml | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/cli/cli/src/rerunFernCliAtVersion.ts b/packages/cli/cli/src/rerunFernCliAtVersion.ts index 8d412baa53b..d5de632c9ec 100644 --- a/packages/cli/cli/src/rerunFernCliAtVersion.ts +++ b/packages/cli/cli/src/rerunFernCliAtVersion.ts @@ -27,7 +27,7 @@ export async function rerunFernCliAtVersion({ ].join("\n") ); - const { failed } = await loggingExeca(cliContext.logger, "npx", ["--quiet", ...commandLineArgs], { + const { failed, stdout, stderr } = await loggingExeca(cliContext.logger, "npx", ["--quiet", ...commandLineArgs], { stdio: "inherit", reject: false, env: { @@ -35,6 +35,13 @@ export async function rerunFernCliAtVersion({ [FERN_CWD_ENV_VAR]: process.env[FERN_CWD_ENV_VAR] ?? process.cwd() } }); + if (stdout.includes("code EEXIST") || stderr.includes("code EEXIST")) { + // try again if there is a npx conflict + return await rerunFernCliAtVersion({ + version, + cliContext + }); + } if (failed) { cliContext.failWithoutThrowing(); diff --git a/packages/cli/cli/versions.yml b/packages/cli/cli/versions.yml index 456f724c1a0..218aa47024e 100644 --- a/packages/cli/cli/versions.yml +++ b/packages/cli/cli/versions.yml @@ -1,3 +1,12 @@ +- changelogEntry: + - summary: | + The Fern CLI now safely handles a npx file exists error by retrying the command on failure. + This error typically happens when two or more instances of the Fern CLI are running `npx` + at the same time. + type: fix + irVersion: 53 + version: 0.41.14-rc0 + - changelogEntry: - summary: | `fern generate --local` no longer crashes on large API Definitions because we