{"record":{"id":"163a1711cf2144fb","repo":"louislam/dockge","slug":"stack-not-found","errorCode":null,"errorMessage":"Stack not found","messagePattern":"Stack not found","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"warning","filePath":"backend/stack.ts","lineNumber":193,"sourceCode":"     * Save the stack to the disk\n     * @param isAdd\n     */\n    async save(isAdd : boolean) {\n        this.validate();\n\n        let dir = this.path;\n\n        // Check if the name is used if isAdd\n        if (isAdd) {\n            if (await fileExists(dir)) {\n                throw new ValidationError(\"Stack name already exists\");\n            }\n\n            // Create the stack folder\n            await fsAsync.mkdir(dir);\n        } else {\n            if (!await fileExists(dir)) {\n                throw new ValidationError(\"Stack not found\");\n            }\n        }\n\n        // Write or overwrite the compose.yaml\n        fs.writeFileSync(path.join(dir, this._composeFileName), this.composeYAML);\n        if (process.env.PUID && process.env.PGID) {\n            const uid = Number(process.env.PUID);\n            const gid = Number(process.env.PGID);\n            fs.lchownSync(dir, uid, gid);\n            fs.chownSync(path.join(dir, this._composeFileName), uid, gid);\n        }\n    }\n\n    async deploy(socket : DockgeSocket) : Promise<number> {\n        const terminalName = getComposeTerminalName(socket.endpoint, this.name);\n        let exitCode = await Terminal.exec(this.server, socket, terminalName, \"docker\", this.getComposeOptions(\"up\", \"-d\", \"--remove-orphans\"), this.path);\n        if (exitCode !== 0) {\n            throw new Error(\"Failed to deploy, please check the terminal output for more information.\");","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/stack.ts#L175-L211","documentation":"Dockge throws this ValidationError from Stack.save() when UPDATING an existing stack (isAdd=false) but the stack's directory does not exist on disk. The update path assumes the folder is present to write compose.yaml into it.","triggerScenarios":"Calling saveStack with isAdd=false for a stack whose directory was deleted externally (manual rm, volume remount, another agent's cleanup) while the UI still had it open.","commonSituations":"Two browser tabs — one deletes the stack while the other saves; host disk/volume recreated in a container losing the stacks dir; editing a stack that was removed via docker compose down + folder rm; wrong agent/endpoint selected so the folder isn't there.","solutions":["Refresh the stack list in the UI and re-open/recreate the stack (the folder is gone)","Check the stacks directory on the connected agent (default ./data/stacks/<name>) and restore the folder if it was deleted accidentally","Verify you are connected to the correct agent endpoint where the stack actually lives","If the stack should be created instead, re-add it with isAdd=true"],"exampleFix":"// before\nawait stack.save(socket, false); // may throw 'Stack not found'\n// after\nconst dir = path.join(stacksDir, name);\nif (!fs.existsSync(path.join(dir, 'compose.yaml'))) {\n    throw new Error(`Stack '${name}' no longer exists; refresh and recreate it`);\n}\nawait stack.save(socket, false);","handlingStrategy":"validation","validationCode":"import { fileExists } from \"./util-common\";\nasync function assertStackDirExists(dir: string) {\n    if (!(await fileExists(dir))) {\n        throw new Error(`Stack folder missing: ${dir} — refresh and recreate`);\n    }\n}\nawait assertStackDirExists(path.join(stacksDir, name));\nawait stack.save(socket, false);","typeGuard":"function stackExists(list: Stack[], name: string): boolean {\n    return list.some(s => s.name === name);\n}","tryCatchPattern":"try {\n    await stack.save(socket, false);\n} catch (e) {\n    if (e instanceof ValidationError && e.message === \"Stack not found\") {\n        // refresh stack list / re-create stack with isAdd=true\n    } else { throw e; }\n}","preventionTips":["Refresh the UI before saving after external folder changes","Don't delete stack folders manually while the UI is open","Use volume persistence for the stacks directory on agents","Verify endpoint/agent selection when managing multi-host setups"],"tags":["validation","filesystem","stack-management"],"backgroundTag":"resource-not-found","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}