{"record":{"id":"571abca5b59af0f7","repo":"slopus/happy","slug":"invalid-session-name-sessionname","errorCode":null,"errorMessage":"Invalid session name: \"${sessionName}\"","messagePattern":"Invalid session name: \"(.+?)\"","errorType":"validation","errorClass":"TmuxSessionIdentifierError","httpStatus":null,"severity":"error","filePath":"packages/happy-cli/src/utils/tmux.ts","lineNumber":969,"sourceCode":"    } catch {\n        return false;\n    }\n}\n\n/**\n * Create a new tmux session with proper typing and validation\n */\nexport async function createTmuxSession(\n    sessionName: string,\n    options?: {\n        windowName?: string;\n        detached?: boolean;\n        attach?: boolean;\n    }\n): Promise<{ success: boolean; sessionIdentifier?: string; error?: string }> {\n    try {\n        if (!sessionName || !/^[a-zA-Z0-9._-]+$/.test(sessionName)) {\n            throw new TmuxSessionIdentifierError(`Invalid session name: \"${sessionName}\"`);\n        }\n\n        const utils = new TmuxUtilities(sessionName);\n        const windowName = options?.windowName || 'main';\n\n        const cmd = ['new-session'];\n        if (options?.detached !== false) {\n            cmd.push('-d');\n        }\n        cmd.push('-s', sessionName);\n        cmd.push('-n', windowName);\n\n        const result = await utils.executeTmuxCommand(cmd);\n        if (result && result.returncode === 0) {\n            const sessionIdentifier: TmuxSessionIdentifier = {\n                session: sessionName,\n                window: windowName\n            };","sourceCodeStart":951,"sourceCodeEnd":987,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/utils/tmux.ts#L951-L987","documentation":"This session-creation helper validates the requested tmux session name against /^[a-zA-Z0-9._-]+$/ before running 'new-session'. Empty names or names with spaces/special characters are rejected with a TmuxSessionIdentifierError because tmux would fail or behave unpredictably.","triggerScenarios":"Calling createSession (the exported helper around tmux.ts:969) with sessionName undefined, empty string '', or containing characters outside [a-zA-Z0-9._-], e.g. 'my project', 'dev:1', 'a/b'.","commonSituations":"Deriving a session name from a project path or branch name that contains spaces or slashes; an unset environment variable producing an empty name; passing a full tmux target string like 'sess:win' where a bare session name is expected.","solutions":["Sanitize the name before calling: replace invalid characters with '.' or '-', e.g. name.replace(/[^a-zA-Z0-9._-]/g, '-').","Provide a non-empty name explicitly instead of deriving it from an optional variable.","Validate with the same regex (/^[a-zA-Z0-9._-]+$/) before the call.","If the name comes from a path, strip directories and replace path separators."],"exampleFix":"// before\nawait createSession(projectPath); // '/Users/me/My Project'\n// after\nconst sessionName = path.basename(projectPath).replace(/[^a-zA-Z0-9._-]/g, '-');\nawait createSession(sessionName);","handlingStrategy":"validation","validationCode":"const SESSION_NAME_RE = /^[a-zA-Z0-9._-]+$/;\nfunction assertValidSessionName(name) {\n  if (!name || !SESSION_NAME_RE.test(name)) {\n    throw new Error(`Session name must match ${SESSION_NAME_RE}, got: ${JSON.stringify(name)}`);\n  }\n}\nassertValidSessionName(sessionName);","typeGuard":"function isValidSessionName(name) {\n  return typeof name === 'string' && name.length > 0 && /^[a-zA-Z0-9._-]+$/.test(name);\n}","tryCatchPattern":"try {\n  await createSession(sessionName, options);\n} catch (e) {\n  if (e instanceof TmuxSessionIdentifierError) {\n    return { success: false, error: `Invalid session name: ${sessionName}` };\n  }\n  throw e;\n}","preventionTips":["Derive tmux names from paths/branches with .replace(/[^a-zA-Z0-9._-]/g, '-').","Never allow empty derived names — fall back to a default like 'main'.","Validate at the CLI/config boundary before names propagate.","Keep the allowed-character regex in one shared constant."],"tags":["tmux","validation","input-validation"],"backgroundTag":"invalid-session-name","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}