Hmbown/CodeWhale · error · RegistryError

invalid_host

invalid_host

Error message

ssh computers need a valid host (letters, digits, dot, dash, underscore)

What it means

RegistryError "invalid_host": when transport is "ssh", register() requires rest.host to be a non-empty string matching ^[A-Za-z0-9._-]+$ — plain hostnames, IPs in dot notation, and dash/underscore names. The host field is passed to an ssh command line, so anything that would need quoting or parsing (user@host, host:port, IPv6, spaces) is rejected.

Solutions

  1. Set host to the bare hostname or IPv4 address, e.g. host: "10.0.0.5".
  2. Move the login name to rest.user and the port to rest.port instead of embedding them in host.
  3. For IPv6 or exotic hostnames, add an /etc/ssh config alias matching [A-Za-z0-9._-]+ and use that alias as host.
  4. Trim whitespace and strip any "ssh://" prefix from the host value before registering.

Example fix

// before
register({ id: "lab", transport: "ssh", host: "alice@10.0.0.5:2222" });
// after
register({ id: "lab", transport: "ssh", host: "10.0.0.5", user: "alice", port: 2222 });
Defensive patterns

Strategy: validation

Validate before calling

const HOST_RE = /^[A-Za-z0-9._-]+$/;
if (typeof host !== "string" || !HOST_RE.test(host)) throw new Error("ssh host must be a bare hostname/IP");

Type guard

const isSshHost = (h) => typeof h === "string" && /^[A-Za-z0-9._-]+$/.test(h);

Try / catch

try {
  register({ id, transport: "ssh", host, user, port });
} catch (e) {
  if (e?.code === "invalid_host") throw new Error(`Host "${host}" rejected; split user@host:port into host/user/port fields`);
  throw e;
}

Prevention

When it happens

Trigger: register({ id: "x", transport: "ssh" }) with no host; host: "user@10.0.0.5" (put user in rest.user); host: "[2001:db8::1]" or "host:22"; host containing spaces or a URL scheme.

Common situations: Copy-pasting an scp/ssh connection string wholesale into host; omitting host because ssh config on the machine would resolve an alias; IPv6 addresses which the regex does not allow.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/cd7cc19e595c1fcc. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/plugins/computer-use/src/registry.mjs:88

  const c = get(id); // throws unknown_computer
  const reg = load();
  reg.active = c.id;
  save(reg);
  return c;
}

/** Register or update a computer. Returns the entry. */
export function register({ id, transport, label, ...rest }) {
  if (!id || !ID_RE.test(id)) throw new RegistryError("invalid_id", "computer id must match " + ID_RE);
  if (!["local", "ssh", "hdc", "docker"].includes(transport)) {
    throw new RegistryError("invalid_transport", "transport must be one of: local, ssh, hdc, docker");
  }
  if (id === "local" && transport !== "local") {
    throw new RegistryError("reserved_id", '"local" is reserved for this machine');
  }
  if (transport === "ssh") {
    if (!rest.host || !/^[A-Za-z0-9._-]+$/.test(rest.host)) {
      throw new RegistryError("invalid_host", "ssh computers need a valid host (letters, digits, dot, dash, underscore)");
    }
    if (rest.port != null && (!Number.isInteger(rest.port) || rest.port < 1 || rest.port > 65535)) {
      throw new RegistryError("invalid_port", "port must be an integer in 1..65535");
    }
    if (rest.user != null && !/^[a-zA-Z0-9._-]+$/.test(rest.user)) {
      throw new RegistryError("invalid_user", "user must be a plain name");
    }
  }
  if (transport === "hdc") {
    if (rest.target != null && !/^[A-Za-z0-9._-]*$/.test(rest.target)) {
      throw new RegistryError("invalid_target", "hdc target key contains invalid characters");
    }
    rest.platform = "harmonyos";
  }
  if (transport === "docker") {
    if (!rest.container || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(rest.container)) {
      throw new RegistryError("invalid_container", "docker computers need a valid container name");
    }

View on GitHub (pinned to 73e0f67d83)