{"record":{"id":"d69634ea18633a44","repo":"louislam/dockge","slug":"stack-name-can-only-contain-a-z-0-9-only","errorCode":null,"errorMessage":"Stack name can only contain [a-z][0-9] _ - only","messagePattern":"Stack name can only contain \\[a-z\\]\\[0-9\\] _ - only","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"backend/stack.ts","lineNumber":117,"sourceCode":"        });\n        if (!res.stdout) {\n            return {};\n        }\n        return JSON.parse(res.stdout.toString());\n    }\n\n    get isManagedByDockge() : boolean {\n        return fs.existsSync(this.path) && fs.statSync(this.path).isDirectory();\n    }\n\n    get status() : number {\n        return this._status;\n    }\n\n    validate() {\n        // Check name, allows [a-z][0-9] _ - only\n        if (!this.name.match(/^[a-z0-9_-]+$/)) {\n            throw new ValidationError(\"Stack name can only contain [a-z][0-9] _ - only\");\n        }\n\n        // Check YAML format\n        yaml.parse(this.composeYAML);\n\n        let lines = this.composeENV.split(\"\\n\");\n\n        // Check if the .env is able to pass docker-compose\n        // Prevent \"setenv: The parameter is incorrect\"\n        // It only happens when there is one line and it doesn't contain \"=\"\n        if (lines.length === 1 && !lines[0].includes(\"=\") && lines[0].length > 0) {\n            throw new ValidationError(\"Invalid .env format\");\n        }\n    }\n\n    get composeYAML() : string {\n        if (this._composeYAML === undefined) {\n            try {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/stack.ts#L99-L135","documentation":"Stack.validate() enforces a naming policy for compose projects: the stack name must fully match /^[a-z0-9_-]+$/, i.e. lowercase letters, digits, underscore, and hyphen only. Docker Compose project names have the same restriction, so any other character (uppercase, spaces, dots, slashes) throws this ValidationError before the stack is saved. It is called from save().","triggerScenarios":"Saving/renaming a stack whose name contains characters outside [a-z0-9_-] — e.g. 'MyStack', 'my stack', 'my.stack', or an empty string.","commonSituations":"Users typing display-style names with capitals or spaces in the UI; deriving stack names from directory paths or image names containing dots/slashes; copied names with trailing whitespace.","solutions":["Rename the stack to lowercase alphanumerics with _ or - only, e.g. 'my-stack-1'.","Normalize before saving: name.toLowerCase().trim().replace(/[^a-z0-9_-]/g, '-').","Validate the name client-side against /^[a-z0-9_-]+$/ before calling save."],"exampleFix":"// before\nstack.name = 'My Stack.app';\nstack.save();\n// after\nstack.name = 'my-stack-app';\nstack.save();","handlingStrategy":"validation","validationCode":"function isValidStackName(name) {\n    return typeof name === 'string' && /^[a-z0-9_-]+$/.test(name);\n}","typeGuard":"function isSafeName(v) { return typeof v === 'string' && /^[a-z0-9_-]+$/.test(v); }","tryCatchPattern":"try {\n    stack.save();\n} catch (e) {\n    if (e.message.includes('Stack name')) {\n        e.message = 'Use lowercase letters, digits, _ or - only';\n        throw e;\n    }\n}","preventionTips":["Normalize names: lowercase, trim, replace invalid chars with '-'","Validate against /^[a-z0-9_-]+$/ in UI before calling save","Avoid deriving stack names from image names or paths with dots/slashes"],"tags":["validation","docker-compose","naming","stack"],"backgroundTag":"invalid-stack-name","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}