{"record":{"id":"c62ae0b80b7689bd","repo":"herdrdev/herdr","slug":"remote-binary-env-var-must-not-be-empty","errorCode":null,"errorMessage":"{REMOTE_BINARY_ENV_VAR} must not be empty","messagePattern":"(.+?) must not be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/remote/attach.rs","lineNumber":897,"sourceCode":"    let version = lines.next().unwrap_or_default().trim();\n    let status = lines.next().unwrap_or_default();\n    Ok(version == format!(\"herdr {}\", current_version())\n        && parse_client_status_json(status)\n            .map(|status| status.protocol == CURRENT_PROTOCOL)\n            .unwrap_or(false))\n}\n\nfn remote_binary_exists(ssh: &RemoteSsh, remote_herdr: &RemoteHerdr) -> io::Result<bool> {\n    let command = format!(\"test -x {}\", remote_herdr.shell_path);\n    Ok(ssh.sh_output(&command)?.status.success())\n}\n\nfn remote_binary_override_path() -> io::Result<Option<PathBuf>> {\n    let Some(value) = std::env::var_os(REMOTE_BINARY_ENV_VAR) else {\n        return Ok(None);\n    };\n    if value.is_empty() {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidInput,\n            format!(\"{REMOTE_BINARY_ENV_VAR} must not be empty\"),\n        ));\n    }\n\n    let path = PathBuf::from(value);\n    let metadata = fs::metadata(&path).map_err(|err| {\n        io::Error::new(\n            err.kind(),\n            format!(\n                \"failed to inspect {REMOTE_BINARY_ENV_VAR} path {}: {err}\",\n                path.display()\n            ),\n        )\n    })?;\n    if !metadata.is_file() {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidInput,","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/herdrdev/herdr/blob/f457cff4f2648eee85d176f8a41861241d4e8428/src/remote/attach.rs#L879-L915","documentation":"remote_binary_override_path reads the REMOTE_BINARY env var (REMOTE_BINARY_ENV_VAR) as an optional override for which Herdr binary to install/verify remotely. If the variable is set but its value is an empty string, it fails with ErrorKind::InvalidInput rather than silently falling back or using an empty path. This catches misconfiguration early.","triggerScenarios":"Setting the Herdr remote-binary override environment variable to an empty value (e.g. `HERDR_REMOTE_BINARY= herdr remote attach ...` or an empty entry in .env/shell profile) and then invoking any remote attach/prepare flow that calls remote_binary_override_path.","commonSituations":"Shell scripts or CI that export the variable conditionally and leave it empty; `.env` files with a `VAR=` line; CI matrices where the variable is defined but unset-for-one-case as empty string.","solutions":["Unset the variable entirely instead of setting it empty: `unset HERDR_REMOTE_BINARY` (or remove the `VAR=` line)","Set it to a real path: `export HERDR_REMOTE_BINARY=/usr/local/bin/herdr`","In scripts, guard with `[[ -n \"$HERDR_REMOTE_BINARY\" ]] && export ...` so empty values never reach Herdr","Fix CI variable definitions to omit the variable rather than define it as empty"],"exampleFix":"# before\nexport HERDR_REMOTE_BINARY=\"\"   # empty -> InvalidInput error\nherdr remote attach host\n\n# after\nunset HERDR_REMOTE_BINARY\nherdr remote attach host","handlingStrategy":"validation","validationCode":"// Before invoking remote attach flows\nif let Some(v) = std::env::var_os(\"HERDR_REMOTE_BINARY\") {\n    if v.is_empty() { std::env::remove_var(\"HERDR_REMOTE_BINARY\"); }\n}","typeGuard":"fn valid_remote_binary_override() -> Option<PathBuf> {\n    std::env::var_os(\"HERDR_REMOTE_BINARY\")\n        .filter(|v| !v.is_empty())\n        .map(PathBuf::from)\n}","tryCatchPattern":"match remote_binary_override_path() {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => { /* unset the empty var and retry with default */ }\n    other => other?,\n}","preventionTips":["Never export the override as an empty string; unset it instead","Guard CI/shell scripts with [[ -n \"$VAR\" ]] before exporting","Validate .env files for empty-valued entries"],"tags":["environment-variable","configuration","remote-attach","invalid-input"],"backgroundTag":"empty-environment-variable","analyzedSha":"f457cff4f2648eee85d176f8a41861241d4e8428","analyzedAt":"2026-08-28T15:41:09.197Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}