{"record":{"id":"31eca406701390b6","repo":"can1357/oh-my-pi","slug":"nameerror","errorCode":null,"errorMessage":"${nameError}","messagePattern":"\\$\\{nameError\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/ssh/config-writer.ts","lineNumber":89,"sourceCode":"\t\treturn \"Host name is too long (max 100 characters)\";\n\t}\n\t// Check for invalid characters (only allow alphanumeric, dash, underscore, dot)\n\tif (!/^[a-zA-Z0-9_.-]+$/.test(name)) {\n\t\treturn \"Host name can only contain letters, numbers, dash, underscore, and dot\";\n\t}\n\treturn undefined;\n}\n\n/**\n * Add an SSH host to a config file.\n *\n * @throws Error if host name already exists or validation fails\n */\nexport async function addSSHHost(filePath: string, name: string, hostConfig: SSHHostConfig): Promise<void> {\n\t// Validate host name\n\tconst nameError = validateHostName(name);\n\tif (nameError) {\n\t\tthrow new Error(nameError);\n\t}\n\n\t// Validate host field\n\tif (!hostConfig.host) {\n\t\tthrow new Error(\"Host address cannot be empty\");\n\t}\n\n\t// Read existing config\n\tconst existing = await readSSHConfigFile(filePath);\n\n\t// Check for duplicate name\n\tif (existing.hosts?.[name]) {\n\t\tthrow new Error(`Host \"${name}\" already exists in ${filePath}`);\n\t}\n\n\t// Add host\n\tconst updated: SSHConfigFile = {\n\t\t...existing,","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/ssh/config-writer.ts#L71-L107","documentation":"addSSHHost validates the host name before modifying an SSH config and rethrows validateHostName's message verbatim. The name must satisfy the library's host-name rules (non-empty, valid pattern); any validation failure aborts the add. This guards against writing entries SSH itself could never match or that would corrupt the config.","triggerScenarios":"Calling addSSHHost(filePath, name, hostConfig) with a name that fails validateHostName — e.g. empty string, whitespace, or characters disallowed for host names.","commonSituations":"Programmatic callers passing unvalidated user input as the host name, GUI/CLI handlers forwarding blank form fields, or names with special characters/tokens meant as patterns but rejected here.","solutions":["Read the message thrown to see which rule failed and correct the name (non-empty, no illegal characters)","Check validateHostName in the same module for the exact accepted pattern","Sanitize/trim user-supplied names before calling addSSHHost"],"exampleFix":"// before\nawait addSSHHost(path, \"\", cfg); // throws\n// after\nconst name = userInput.trim();\nif (!validateHostName(name)) await addSSHHost(path, name, cfg);","handlingStrategy":"validation","validationCode":"const err = validateHostName(name);\nif (err) throw new Error(`invalid host name: ${err}`);\nawait addSSHHost(filePath, name, hostConfig);","typeGuard":"null","tryCatchPattern":"try { await addSSHHost(p, name, cfg); } catch (e) { if (!(e instanceof Error) || e.message !== nameError) throw e; }","preventionTips":["Run validateHostName before any addSSHHost call","Trim and sanitize user input used as host names","Check the validateHostName rules for allowed characters"],"tags":["ssh","validation","host-name"],"backgroundTag":"ssh-host-name-validation","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}