{"record":{"id":"eaac3022ecac0115","repo":"oxc-project/oxc","slug":"stream-did-not-contain-valid-utf-8","errorCode":null,"errorMessage":"stream did not contain valid UTF-8","messagePattern":"stream did not contain valid UTF-8","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/utils/mod.rs","lineNumber":152,"sourceCode":"pub fn starts_with_ignore_case(haystack: &str, prefix: &str) -> bool {\n    let len = prefix.len();\n    if haystack.len() < len {\n        return false;\n    }\n    haystack.as_bytes()[..len].eq_ignore_ascii_case(prefix.as_bytes())\n}\n\n/// Reads the content of a path and returns it.\n/// This function is faster than native `fs:read_to_string`.\n///\n/// # Errors\n/// When the content of the path is not a valid UTF-8 bytes\npub fn read_to_string(path: &Path) -> io::Result<String> {\n    // `simdutf8` is faster than `std::str::from_utf8` which `fs::read_to_string` uses internally\n    let bytes = std::fs::read(path)?;\n    if simdutf8::basic::from_utf8(&bytes).is_err() {\n        // Same error as `fs::read_to_string` produces (`io::Error::INVALID_UTF8`)\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"stream did not contain valid UTF-8\",\n        ));\n    }\n    // SAFETY: `simdutf8` has ensured it's a valid UTF-8 string\n    Ok(unsafe { String::from_utf8_unchecked(bytes) })\n}\n\n/// Read the contents of a UTF-8 encoded file directly into arena allocator.\n/// Avoids intermediate allocations if file size is known in advance.\n///\n/// This function opens the file at `path`, reads its entire contents into memory\n/// allocated from the given [`Allocator`], validates that the bytes are valid UTF-8,\n/// and returns a borrowed `&str` pointing to the allocator-backed data.\n///\n/// This is useful for performance-critical workflows where zero-copy string handling is desired,\n/// such as parsing large source files in memory-constrained or throughput-sensitive environments.\n///","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/utils/mod.rs#L134-L170","documentation":"Returned by the linter's fast read_to_string helper: the file's raw bytes were read successfully but simdutf8::basic::from_utf8 rejected them, and the failure is re-wrapped as io::ErrorKind::InvalidData with std's standard message. The input at fault is a source file whose encoding is not valid UTF-8 (e.g. Latin-1, UTF-16, or a stray invalid byte).","triggerScenarios":"Thrown at crates/oxc_linter/src/utils/mod.rs:152 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-encode or save the file as UTF-8","Convert the file lossily (e.g. String::from_utf8_lossy) if replacement characters are acceptable","Detect a UTF-16 BOM and transcode before validation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}