nikivdev/code · error
unhash output missing hash
Error message
unhash output missing hash
What it means
run computes a hash via an external command (unhash/hash tool), reads the first non-empty stdout line, and throws this error when the output has no lines at all. It protects the LINK_PREFIX link construction from an empty hash.
Source
Thrown at src/hash.rs:40
if env::var("UNHASH_KEY").is_err() {
if let Ok(Some(value)) = flow_env::get_personal_env_var("UNHASH_KEY") {
cmd.env("UNHASH_KEY", value);
}
}
let output = cmd.output().context("failed to run unhash")?;
if !output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
bail!("unhash failed: {}\n{}{}", output.status, stdout, stderr);
}
let stdout = String::from_utf8_lossy(&output.stdout);
let mut lines = stdout.lines().filter(|line| !line.trim().is_empty());
let hash = lines
.next()
.ok_or_else(|| anyhow::anyhow!("unhash output missing hash"))?
.trim()
.to_string();
let link = format!("{LINK_PREFIX}{hash}");
copy_to_clipboard(&link)?;
println!("{hash}");
println!("{link}");
if let Some(path_line) = lines.next() {
println!("{}", path_line.trim());
}
Ok(())
}
fn copy_to_clipboard(text: &str) -> Result<()> {
if std::env::var("FLOW_NO_CLIPBOARD").is_ok() || !std::io::stdin().is_terminal() {View on GitHub (pinned to a747e741ae)
Solutions
- Check the command's stderr/exit status and surface it instead of stdout alone
- Verify the hash tool is installed and on PATH and produces output for your input
- Ensure you pass non-empty input to hash
Example fix
// before
let hash = lines.next().ok_or_else(|| anyhow::anyhow!("unhash output missing hash"))?;
// after
if !output.status.success() {
anyhow::bail!("hash command failed: {}", String::from_utf8_lossy(&output.stderr));
}
let hash = lines.next().ok_or_else(|| anyhow::anyhow!("unhash output missing hash"))?; Defensive patterns
Strategy: try-catch
Validate before calling
let out = Command::new("f").args(["hash", input]).output()?;
if !out.status.success() || out.stdout.iter().all(|&b| b.is_ascii_whitespace()) {
anyhow::bail!("hash tool produced no output: {}", String::from_utf8_lossy(&out.stderr));
} Try / catch
match run(input) {
Err(e) if e.to_string().contains("missing hash") => {
eprintln!("hash tool returned empty output; check stderr of the hash command");
}
other => other?,
} Prevention
- Check exit status/stderr of external commands, not just stdout
- Pin/verify the hash tool version your parser expects
- Never pipe empty input into hash
When it happens
Trigger: The underlying hash command exits with empty stdout (failed silently, wrong subcommand, empty input) so lines.next() is None.
Common situations: Hash tool not installed or returning empty due to error on stderr, piping empty input, version change that renamed the output field.
Related errors
- gen returned no output
- No exchanges found in session
- resolver {} failed for {}: {}
- resolver {} returned empty output for {}
- AI returned an empty response.
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/09002e8a1a90bfe3.
Report an issue: GitHub.