diff --git a/packages/local-config-updater/src/index.ts b/packages/local-config-updater/src/index.ts index dda8846cc..4e0bb47d9 100644 --- a/packages/local-config-updater/src/index.ts +++ b/packages/local-config-updater/src/index.ts @@ -98,7 +98,12 @@ function writeFileAtomic(configFilePath: string, content: string): void { mkdirSync(dir, { recursive: true }); const tempPath = path.join(dir, `.stack.config.${Math.random().toString(36).slice(2)}.tmp`); writeFileSync(tempPath, content, "utf-8"); - renameSync(tempPath, configFilePath); + try { + renameSync(tempPath, configFilePath); + } catch (error) { + try { rmSync(tempPath); } catch { /* best-effort cleanup */ } + throw error; + } } function renderConfigObjectToFile(configFilePath: string, config: Config): void {