{"record":{"id":"986193a8b8a86938","repo":"ducaale/xh","slug":"invalid-utf-8","errorCode":null,"errorMessage":"Invalid UTF-8","messagePattern":"Invalid UTF-8","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/to_curl.rs","lineNumber":176,"sourceCode":"        cmd.opt(\"-N\", \"--no-buffer\");\n    }\n    // Since --fail is more disruptive than HTTPie's --check-status flag, we will not enable\n    // it unless the user explicitly sets the latter flag\n    if args.check_status == Some(true) {\n        // Suppresses output on failure, unlike us\n        cmd.opt(\"-f\", \"--fail\");\n    }\n\n    // HTTP options\n    if args.follow {\n        cmd.opt(\"-L\", \"--location\");\n    }\n    if let Some(num) = args.max_redirects {\n        cmd.arg(\"--max-redirs\");\n        cmd.arg(num.to_string());\n    }\n    if let Some(filename) = args.output {\n        let filename = filename.to_str().ok_or_else(|| anyhow!(\"Invalid UTF-8\"))?;\n        cmd.opt(\"-o\", \"--output\");\n        cmd.arg(filename);\n    } else if args.download {\n        cmd.opt(\"-O\", \"--remote-name\");\n    }\n    if args.resume {\n        cmd.opt(\"-C\", \"--continue-at\");\n        cmd.arg(\"-\"); // Tell curl to guess, like we do\n    }\n    match args.verify.unwrap_or(Verify::Yes) {\n        Verify::CustomCaBundle(filename) => {\n            cmd.arg(\"--cacert\");\n            cmd.arg(filename);\n        }\n        Verify::No => {\n            cmd.opt(\"-k\", \"--insecure\");\n        }\n        Verify::Yes => {}","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/to_curl.rs#L158-L194","documentation":"The curl translation layer builds a command line whose -o/--output argument must be a valid UTF-8 string. Path arguments on Unix can be arbitrary bytes; when args.output is not valid UTF-8, translate returns this error instead of emitting a malformed curl command.","triggerScenarios":"Passing -o/--output a filename containing invalid UTF-8 bytes (common with OS-supplied names from a non-UTF-8 locale or corrupted filenames), then running `xh --curl`/print_curl_translation.","commonSituations":"Linux systems with filenames that are raw bytes from another encoding (Latin-1, SJIS); shell variables expanded from file listings with mojibake; scripts on systems without UTF-8 locale.","solutions":["Rename the output file to valid UTF-8 before translating","Run with a UTF-8 locale (e.g. LANG=C.UTF-8) so paths decode correctly","Fix the source of the filename (e.g. ls/find output) to produce valid UTF-8","Skip curl translation for that invocation and download directly with xh"],"exampleFix":"// before\nxh --curl -o \"$RAW_BYTES_NAME\" https://example.org\n// after\nexport LANG=C.UTF-8\nxh --curl -o output.bin https://example.org","handlingStrategy":"validation","validationCode":"if !std::str::from_utf8(output_path.as_os_str().as_encoded_bytes()).is_ok() {\n    eprintln!(\"output filename must be valid UTF-8 for --curl translation\");\n    std::process::exit(2);\n}","typeGuard":"fn is_utf8_path(p: &std::path::Path) -> bool {\n    p.to_str().is_some()\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string() == \"Invalid UTF-8\" => {\n        eprintln!(\"rename output file to valid UTF-8\");\n    }\n    r => r?,\n}","preventionTips":["Keep filenames ASCII/UTF-8 when scripting around xh","Run in a UTF-8 locale (LANG=C.UTF-8)","Avoid passing raw byte filenames from ls/find output"],"tags":["cli","encoding","utf-8","curl"],"backgroundTag":"invalid-argument-format","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}