From 992ea1331646122df4a92e66560de5ec0d23f122 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2026 23:48:19 +0000 Subject: [PATCH] fix: clean up temp file if renameSync fails in writeFileAtomic Co-Authored-By: mantra --- packages/local-config-updater/src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 {