can1357/oh-my-pi · error

${nameError}

Error message

${nameError}

What it means

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.

Source

Thrown at packages/coding-agent/src/ssh/config-writer.ts:89

		return "Host name is too long (max 100 characters)";
	}
	// Check for invalid characters (only allow alphanumeric, dash, underscore, dot)
	if (!/^[a-zA-Z0-9_.-]+$/.test(name)) {
		return "Host name can only contain letters, numbers, dash, underscore, and dot";
	}
	return undefined;
}

/**
 * Add an SSH host to a config file.
 *
 * @throws Error if host name already exists or validation fails
 */
export async function addSSHHost(filePath: string, name: string, hostConfig: SSHHostConfig): Promise<void> {
	// Validate host name
	const nameError = validateHostName(name);
	if (nameError) {
		throw new Error(nameError);
	}

	// Validate host field
	if (!hostConfig.host) {
		throw new Error("Host address cannot be empty");
	}

	// Read existing config
	const existing = await readSSHConfigFile(filePath);

	// Check for duplicate name
	if (existing.hosts?.[name]) {
		throw new Error(`Host "${name}" already exists in ${filePath}`);
	}

	// Add host
	const updated: SSHConfigFile = {
		...existing,

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the message thrown to see which rule failed and correct the name (non-empty, no illegal characters)
  2. Check validateHostName in the same module for the exact accepted pattern
  3. Sanitize/trim user-supplied names before calling addSSHHost

Example fix

// before
await addSSHHost(path, "", cfg); // throws
// after
const name = userInput.trim();
if (!validateHostName(name)) await addSSHHost(path, name, cfg);
Defensive patterns

Strategy: validation

Validate before calling

const err = validateHostName(name);
if (err) throw new Error(`invalid host name: ${err}`);
await addSSHHost(filePath, name, hostConfig);

Type guard

null

Try / catch

try { await addSSHHost(p, name, cfg); } catch (e) { if (!(e instanceof Error) || e.message !== nameError) throw e; }

Prevention

When it happens

Trigger: Calling addSSHHost(filePath, name, hostConfig) with a name that fails validateHostName — e.g. empty string, whitespace, or characters disallowed for host names.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/31eca406701390b6. Report an issue: GitHub.