sxyazi/yazi · error
--target must be valid UTF-8
Error message
--target must be valid UTF-8
What it means
The ya build tool's --target argument is read as an OsString and converted to String. If the value is not valid UTF-8, target() fails with "--target must be valid UTF-8". The tool only supports UTF-8 target triples.
Solutions
- Pass a plain UTF-8 target triple, e.g. --target x86_64-unknown-linux-gnu.
- Check the argument source (script/env var) for non-UTF-8 bytes: `printf '%s' "$TGT" | xxd`.
- Set a UTF-8 locale (e.g. LANG=C.UTF-8) and retype the argument.
Example fix
// before ya pack --build --target $TGT # TGT contains invalid bytes // after ya pack --build --target x86_64-unknown-linux-gnu
Defensive patterns
Strategy: validation
Validate before calling
# shell if ! printf '%s' "$TGT" | iconv -f utf-8 -t utf-8 >/dev/null 2>&1; then echo "TGT is not valid UTF-8"; exit 1 fi
Prevention
- Always pass explicit literal target triples.
- Quote and audit shell variables interpolated into --target.
- Use a UTF-8 locale when invoking the tool.
When it happens
Trigger: Passing --target with a value containing invalid UTF-8 bytes on the command line (possible on Unix where args are OsString).
Common situations: Shell variables or scripts interpolating corrupted bytes into the argument; copy-pasted target strings with unusual encodings; exotic locale environments.
Related errors
- --bin-dir is only valid for the install task
- the dist task requires --target
- chafa failed with status
- Failed to get the C string from CFString
- process exited with status
AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02).
Data as JSON: /api/errors/453abfe2ac04157d.
Report an issue: GitHub.
Appendix: source
Thrown at yazi-build/src/args.rs:54
Ok(Self::Dest(target))
}
Some("install") => {
ensure!(target.is_empty(), "--target is not valid for the install task");
Ok(Self::Install(bin_dir))
}
Some("--help") => Ok(Self::Help),
_ => bail!("unknown task: {}", task.display()),
}
}
fn value(args: &mut impl Iterator<Item = OsString>, option: &str) -> Result<OsString> {
args.next().with_context(|| format!("missing value for {option}"))
}
fn target(args: &mut impl Iterator<Item = OsString>) -> Result<String> {
Self::value(args, "--target")?
.into_string()
.map_err(|_| anyhow!("--target must be valid UTF-8"))
}
}
View on GitHub (pinned to 5f901b886b)