{"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":"anyhow::Error","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/94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2/yazi-build/src/args.rs#L36-L57","documentation":"yazi-build's CLI parser reads --target as an OsString and converts it to String with into_string(). On failure (the OS string contains bytes that are not valid UTF-8) it bails with \"--target must be valid UTF-8\". Target triples are forwarded to cargo/rustc, which expect UTF-8, so the value cannot be used as-is.","triggerScenarios":"Invoking the build tool with a --target value containing non-UTF-8 bytes — a mangled locale, a triple generated from unvalidated external data, or hidden bytes pasted into the shell.","commonSituations":"Broken terminal/shell encoding; scripts composing --target from file contents or environment variables that are not guaranteed UTF-8.","solutions":["Retype the target cleanly as plain ASCII, e.g. --target x86_64-unknown-linux-gnu","If the string looks correct but still fails, check the shell/locale encoding and re-run under a UTF-8 locale"],"exampleFix":"# before (target.txt has invalid bytes)\nyazi-build build --target $(cat target.txt)\n\n# after (plain ASCII triple)\nyazi-build build --target x86_64-unknown-linux-gnu","handlingStrategy":"validation","validationCode":"// Validate before invoking the build tool:\nif let Some(t) = &target_os_string {\n    ensure!(t.to_str().is_some(), \"--target must be valid UTF-8\");\n}","typeGuard":"fn is_valid_target(s: &std::ffi::OsStr) -> bool { s.to_str().is_some() }","tryCatchPattern":null,"preventionTips":["Pass target triples as plain ASCII literals","Do not build --target from unvalidated external data","Fix the terminal/locale encoding if valid-looking strings keep failing"],"tags":["build","cli","args","utf-8"],"backgroundTag":null,"analyzedSha":"94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2","analyzedAt":"2026-08-16T09:56:24.836Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}