{"record":{"id":"1c718d9c0dafed0e","repo":"uutils/coreutils","slug":"utf-8-error","errorCode":null,"errorMessage":"UTF-8 error","messagePattern":"UTF-8 error","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/uucore/src/lib/lib.rs","lineNumber":573,"sourceCode":"\n/// Equivalent to `std::BufRead::lines` which outputs each line as a `Vec<u8>`,\n/// which avoids panicking on non UTF-8 input.\nfn read_byte_lines<R: std::io::Read>(\n    mut buf_reader: BufReader<R>,\n) -> impl Iterator<Item = error::UResult<Vec<u8>>> {\n    iter::from_fn(move || {\n        let mut buf = Vec::with_capacity(256);\n\n        match buf_reader.read_until(b'\\n', &mut buf) {\n            Ok(0) => None,\n            Err(e) => Some(Err(e.into())),\n            Ok(_) => {\n                // Trim (\\r)\\n\n                if buf.ends_with(b\"\\n\") {\n                    buf.pop();\n                    if buf.ends_with(b\"\\r\") {\n                        buf.pop();\n                    }\n                }\n\n                Some(Ok(buf))\n            }\n        }\n    })\n}\n\n/// Equivalent to `std::BufRead::lines` which outputs each line as an `OsString`.\n///\n/// On platforms where `OsString` cannot contain arbitrary bytes,\n/// non-UTF8 inputs are reported as an error.\npub fn read_os_string_lines<R: std::io::Read>(\n    buf_reader: BufReader<R>,\n) -> impl Iterator<Item = error::UResult<OsString>> {\n    read_byte_lines(buf_reader).map(|byte_line_res| byte_line_res.and_then(os_string_from_vec))\n}\n","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/uutils/coreutils/blob/85295bbf788bfd7a6926ba692031563504b304b7/src/uucore/src/lib/lib.rs#L555-L591","documentation":"Error \"UTF-8 error\" thrown in uutils/coreutils.","triggerScenarios":"Occurs when uucore encounters byte sequences that are not valid UTF-8 where UTF-8 text is required.","commonSituations":"Processing non-UTF-8 file names, arguments, or file contents in a UTF-8-only code path.","solutions":["Ensure the string data is valid UTF-8 before conversion; sanitize or lossy-convert invalid input.","Avoid constructing String from arbitrary byte buffers without validation."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"85295bbf788bfd7a6926ba692031563504b304b7","analyzedAt":"2026-08-19T21:43:27.871Z","contentChangedAt":"2026-08-19T21:43:27.871Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}