{"record":{"id":"d41bfe23bce9bde7","repo":"nikivdev/code","slug":"failed-to-decode-json-line-with-simd-json-err","errorCode":null,"errorMessage":"failed to decode json line with simd-json: {err}","messagePattern":"failed to decode json line with simd-json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/json_parse.rs","lineNumber":14,"sourceCode":"use anyhow::{Result, anyhow};\nuse serde::de::DeserializeOwned;\n\n#[inline]\npub fn parse_json_line<T: DeserializeOwned>(line: &str) -> Result<T> {\n    #[cfg(all(\n        feature = \"linux-host-simd-json\",\n        target_os = \"linux\",\n        any(target_arch = \"x86_64\", target_arch = \"aarch64\")\n    ))]\n    {\n        let mut buf = line.as_bytes().to_vec();\n        return simd_json::serde::from_slice(&mut buf)\n            .map_err(|err| anyhow!(\"failed to decode json line with simd-json: {err}\"));\n    }\n\n    #[cfg(not(all(\n        feature = \"linux-host-simd-json\",\n        target_os = \"linux\",\n        any(target_arch = \"x86_64\", target_arch = \"aarch64\")\n    )))]\n    {\n        serde_json::from_str(line).map_err(|err| anyhow!(\"failed to decode json line: {err}\"))\n    }\n}\n\n#[inline]\npub fn parse_json_bytes_in_place<T: DeserializeOwned>(bytes: &mut [u8]) -> Result<T> {\n    #[cfg(all(\n        feature = \"linux-host-simd-json\",\n        target_os = \"linux\",\n        any(target_arch = \"x86_64\", target_arch = \"aarch64\")","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/json_parse.rs#L1-L32","documentation":"parse_json_line decodes a single JSON line into T. On linux x86_64/aarch64 with the linux-host-simd-json feature, it uses simd-json for speed; when simd_json::serde::from_slice fails, this error wraps the simd-json error. Note simd-json can be stricter than serde_json (e.g. requires mutable buffer, different number handling).","triggerScenarios":"A line of log/output is fed to parse_json_line under the simd-json build and is not valid JSON, is truncated, or has a type mismatch with T.","commonSituations":"Partially written or truncated log lines; the stream emits non-JSON lines (plain text, empty line); schema drift between producer and consumer struct.","solutions":["Log/print the offending line and the wrapped simd-json error to see the exact offset/reason","Verify the line is complete, non-empty JSON before parsing","Compare struct T with the actual JSON shape (field names/types)","If simd-json strictness is the issue, test the same input without the linux-host-simd-json feature"],"exampleFix":"// before\nlet v: Event = parse_json_line(line)?; // panics-equivalent on blank line\n// after\nif line.trim().is_empty() { return Ok(None); }\nlet v: Event = parse_json_line(line)?;","handlingStrategy":"try-catch","validationCode":"fn is_plausible_json(line: &str) -> bool {\n    let t = line.trim();\n    !t.is_empty() && (t.starts_with('{') || t.starts_with('['))\n}","typeGuard":"fn looks_like_json_object(s: &str) -> bool {\n    s.trim_start().starts_with('{') && s.trim_end().ends_with('}')\n}","tryCatchPattern":"match parse_json_line::<Event>(line) {\n    Ok(v) => handle(v),\n    Err(e) if e.to_string().contains(\"simd-json\") => {\n        eprintln!(\"skipping malformed line: {e:#}\"); // or buffer for retry\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Skip blank or non-JSON-prefixed lines before parsing","Ensure writers flush complete lines","Pin producer/consumer schema versions together","Test parsing with both simd-json and serde backends"],"tags":["json","simd-json","deserialization"],"backgroundTag":"json-decode-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}