fix(stacks): return a handled response when saving env to a stack with no env file (#1393)

PUT /api/stacks/:stackName/env resolved no env path when a stack had a
compose file but no .env on disk. It then wrote to an undefined path,
which threw and surfaced as an opaque 500. Guard the missing-env case
and return a clean 404 so direct API callers get an actionable response
instead of a crash. The editor still only edits an existing env file, so
behavior in the UI is unchanged.
This commit is contained in:
Anso
2026-06-19 00:44:36 -04:00
committed by GitHub
parent 2821e87d3f
commit 29c599d370
2 changed files with 26 additions and 0 deletions
+8
View File
@@ -644,6 +644,14 @@ stacksRouter.put('/:stackName/env', async (req: Request, res: Response) => {
}
}
// No env file resolved: the stack has no .env yet and the editor only edits
// an existing env file. GET treats this same case as an empty 200; PUT cannot,
// since there is no resolved path to write. Reply with a clean, handled response
// instead of writing to an undefined path, which would otherwise surface as an opaque 500.
if (!envPath) {
return res.status(404).json({ error: 'No env file exists for this stack' });
}
const fsService = FileSystemService.getInstance(req.nodeId);
const expectedMtimeMs = parseIfMatchMtime(req.header('if-match'));
const result = await fsService.writeFileIfUnchanged(envPath, content, expectedMtimeMs);