{"record":{"id":"cc280985663b1cf5","repo":"nikivdev/code","slug":"failed-to-decode-json-line-err","errorCode":null,"errorMessage":"failed to decode json line: {err}","messagePattern":"failed to decode json line: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/json_parse.rs","lineNumber":23,"sourceCode":"pub 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\")\n    ))]\n    {\n        return simd_json::serde::from_slice(bytes)\n            .map_err(|err| anyhow!(\"failed to decode json bytes with simd-json: {err}\"));\n    }\n\n    #[cfg(not(all(\n        feature = \"linux-host-simd-json\",\n        target_os = \"linux\",","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/json_parse.rs#L5-L41","documentation":"parse_json_line's fallback path uses serde_json::from_str when the simd-json feature/target combination is not active. On decode failure it wraps the serde_json error as \"failed to decode json line: {err}\". Same contract as the simd path, different backend.","triggerScenarios":"A malformed or truncated JSON line is passed to parse_json_line on non-Linux, non-x86_64/aarch64 targets, or builds without the linux-host-simd-json feature.","commonSituations":"Log lines split across flushes; producer emits non-JSON output (warnings, banners) interleaved with JSON lines; consumer struct out of sync with producer schema.","solutions":["Inspect the wrapped serde_json error for position and reason","Ensure lines are complete JSON before parsing (line buffering)","Skip or quarantine non-JSON lines instead of failing the whole stream","Verify the consumer struct matches the producer's JSON schema"],"exampleFix":"// before\nlines.map(|l| parse_json_line::<Event>(&l)).collect::<Result<Vec<_>>>()?\n// after\nlet events = lines.filter_map(|l| {\n    let l = l.trim();\n    (!l.is_empty() && l.starts_with('{')).then_some(l)\n}).map(|l| parse_json_line::<Event>(l)).collect::<Result<Vec<_>>>()?;","handlingStrategy":"try-catch","validationCode":"fn is_complete_json_line(line: &str) -> bool {\n    let t = line.trim();\n    !t.is_empty() && serde_json::from_str::<serde_json::Value>(t).is_ok()\n}","typeGuard":null,"tryCatchPattern":"match parse_json_line::<Event>(line) {\n    Ok(v) => handle(v),\n    Err(e) => {\n        eprintln!(\"bad json line: {e:#}; line={line:.200}\");\n        // quarantine and continue\n    }\n}","preventionTips":["Handle partial lines from buffered streams (wait for newline)","Filter non-JSON producer output before the parser","Add serde(deny_unknown_fields) thoughtfully; keep structs in sync with the schema","Log failing lines with truncation for diagnostics"],"tags":["json","serde","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"}