Hmbown/CodeWhale · error · RegistryError
invalid_target
invalid_target
Error message
hdc target key contains invalid characters
What it means
RegistryError "invalid_target": for hdc transports, an optional rest.target must match ^[A-Za-z0-9._-]*$ (note: empty is allowed because the regex uses *). The target is the hdc device key passed on the hdc command line, so colons (as in connect-style addresses) and other punctuation are rejected. A valid registration also sets platform to "harmonyos".
Solutions
- Use the plain serial/key as printed by `hdc list targets` without host:port — connect first via hdc tconn, then reference the connected key that conforms.
- Omit target to let hdc pick the single connected device.
- Sanitize the target: replace disallowed characters or connect by TCP and use the resulting registry key.
- If you need a colon-bearing address, set up a name/alias at the hdc layer rather than embedding it here.
Example fix
// before
register({ id: "phone", transport: "hdc", target: "192.168.1.10:5555" });
// after
// run `hdc tconn 192.168.1.10:5555` once, then use the listed key
register({ id: "phone", transport: "hdc", target: "192.168.1.10+5555" }); Defensive patterns
Strategy: validation
Validate before calling
const TARGET_RE = /^[A-Za-z0-9._-]*$/;
if (target != null && (typeof target !== "string" || !TARGET_RE.test(target))) throw new Error("hdc target contains invalid characters (no colons)"); Type guard
const isHdcTarget = (t) => typeof t === "string" && /^[A-Za-z0-9._-]*$/.test(t);
Try / catch
try {
register(cfg);
} catch (e) {
if (e?.code === "invalid_target") throw new Error(`Target "${cfg.target}" rejected; connect via hdc tconn and use the key from hdc list targets`);
throw e;
} Prevention
- Use keys from `hdc list targets`, not raw host:port addresses
- Run `hdc tconn host:port` once, then register the resulting key
- Omit target when only one device is connected
- Remember the colon in wireless addresses is the usual offender
When it happens
Trigger: register({ id: "phone", transport: "hdc", target: "192.168.1.10:5555" }) (colon in wireless hdc address); target containing spaces or "+"; target from a mixed device list that includes adb serials with other separators.
Common situations: Using the host:port form shown by `hdc tconn` output directly as target; switching an existing adb-based config (serials may contain other characters) over to hdc.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/071a6e95d4b33190.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/plugins/computer-use/src/registry.mjs:99
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");
}
// Spawned containers always run the Linux desktop image.
rest.platform = rest.platform ?? "linux";
}
const reg = load();
const prev = reg.computers[id];
reg.computers[id] = {
...prev,
id,
transport,
label: label ?? prev?.label ?? id,
registeredAt: prev?.registeredAt ?? new Date().toISOString(),View on GitHub (pinned to 73e0f67d83)