{"record":{"id":"eca81ec9d97dcde7","repo":"vectordotdev/vector","slug":"failed-to-convert-osstr-to-str-for-input-path","errorCode":null,"errorMessage":"Failed to convert OsStr to &str for: {input_path:?}","messagePattern":"Failed to convert OsStr to &str for: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/convert_config.rs","lineNumber":119,"sourceCode":"            }\n        }\n    }\n}\n\nfn convert_config(\n    input_path: &Path,\n    output_path: &Path,\n    output_format: Format,\n) -> Result<(), Vec<String>> {\n    if output_path.exists() {\n        return Err(vec![format!(\"Output path {output_path:?} exists\")]);\n    }\n    let input_format = match Format::from_str(\n        input_path\n            .extension()\n            .unwrap_or_else(|| panic!(\"Failed to get extension for: {input_path:?}\"))\n            .to_str()\n            .unwrap_or_else(|| panic!(\"Failed to convert OsStr to &str for: {input_path:?}\")),\n    ) {\n        Ok(format) => format,\n        Err(_) => return Ok(()), // skip irrelevant files\n    };\n\n    if input_format == output_format {\n        return Ok(());\n    }\n\n    #[allow(clippy::print_stdout)]\n    {\n        println!(\"Converting {input_path:?} config to {output_format:?}.\");\n    }\n    let file_contents = fs::read_to_string(input_path).map_err(|e| vec![e.to_string()])?;\n    let builder: ConfigBuilder = format::deserialize(&file_contents, input_format)?;\n    let config = builder.build()?;\n    let output_string = format::serialize(&config, output_format).map_err(|e| vec![e])?;\n    fs::write(output_path, output_string).map_err(|e| vec![e.to_string()])?;","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/convert_config.rs#L101-L137","documentation":"After obtaining the extension as an OsStr, convert_config converts it to &str; this fails only when the extension is not valid UTF-8. In that case it panics with 'Failed to convert OsStr to &str for: <path>'.","triggerScenarios":"Input file paths containing non-UTF-8 bytes in the extension, typically from filenames created with a non-UTF-8 locale or raw bytes (common on some Linux systems).","commonSituations":"Files downloaded or extracted from archives with non-UTF-8 names, Samba/NFS-mounted shares with legacy encodings, or filenames with corrupt byte sequences in the extension.","solutions":["Rename the file to use a plain ASCII/UTF-8 extension (e.g. mv 'file.$\\xff' file.yaml)","Check the filename bytes with `ls | cat -v` or `printf '%s' | iconv` and fix the encoding","Patch the tool to use to_string_lossy() and skip or error on non-UTF-8 extensions gracefully"],"exampleFix":"// before\n.unwrap_or_else(|| panic!(\"Failed to convert OsStr to &str for: {input_path:?}\"))\n// after\n.unwrap_or_else(|| {\n    eprintln!(\"Skipping non-UTF-8 path: {input_path:?}\");\n    \"\"\n})","handlingStrategy":"validation","validationCode":"fn is_utf8_ext(p: &std::path::Path) -> bool {\n    p.extension().map(|e| e.to_str().is_some()).unwrap_or(false)\n}","typeGuard":"fn utf8_ext(p: &std::path::Path) -> Option<&str> { p.extension()?.to_str() }","tryCatchPattern":null,"preventionTips":["Rename files with non-UTF-8 extensions to plain ASCII names","Normalize filesystem encodings (UTF-8 locales) before ingesting file trees","Detect bad names early: `convmv -f latin1 -t utf8 -r <dir> --notest` style checks"],"tags":["rust","panic","encoding","utf-8"],"backgroundTag":"invalid-argument-format","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}