{"record":{"id":"453abfe2ac04157d","repo":"sxyazi/yazi","slug":"target-must-be-valid-utf-8","errorCode":null,"errorMessage":"--target must be valid UTF-8","messagePattern":"--target must be valid UTF-8","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-build/src/args.rs","lineNumber":54,"sourceCode":"\t\t\t\tOk(Self::Dest(target))\n\t\t\t}\n\t\t\tSome(\"install\") => {\n\t\t\t\tensure!(target.is_empty(), \"--target is not valid for the install task\");\n\t\t\t\tOk(Self::Install(bin_dir))\n\t\t\t}\n\t\t\tSome(\"--help\") => Ok(Self::Help),\n\t\t\t_ => bail!(\"unknown task: {}\", task.display()),\n\t\t}\n\t}\n\n\tfn value(args: &mut impl Iterator<Item = OsString>, option: &str) -> Result<OsString> {\n\t\targs.next().with_context(|| format!(\"missing value for {option}\"))\n\t}\n\n\tfn target(args: &mut impl Iterator<Item = OsString>) -> Result<String> {\n\t\tSelf::value(args, \"--target\")?\n\t\t\t.into_string()\n\t\t\t.map_err(|_| anyhow!(\"--target must be valid UTF-8\"))\n\t}\n}\n","sourceCodeStart":36,"sourceCodeEnd":57,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-build/src/args.rs#L36-L57","documentation":"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.","triggerScenarios":"Passing --target with a value containing invalid UTF-8 bytes on the command line (possible on Unix where args are OsString).","commonSituations":"Shell variables or scripts interpolating corrupted bytes into the argument; copy-pasted target strings with unusual encodings; exotic locale environments.","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."],"exampleFix":"// before\nya pack --build --target $TGT   # TGT contains invalid bytes\n// after\nya pack --build --target x86_64-unknown-linux-gnu","handlingStrategy":"validation","validationCode":"# shell\nif ! printf '%s' \"$TGT\" | iconv -f utf-8 -t utf-8 >/dev/null 2>&1; then\n  echo \"TGT is not valid UTF-8\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass explicit literal target triples.","Quote and audit shell variables interpolated into --target.","Use a UTF-8 locale when invoking the tool."],"tags":["cli","utf-8","build"],"backgroundTag":"invalid-utf8","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}