{"record":{"id":"d1236c7ea0a5b89c","repo":"nikivdev/code","slug":"failed-to-decode-json-bytes-with-simd-json-err","errorCode":null,"errorMessage":"failed to decode json bytes with simd-json: {err}","messagePattern":"failed to decode json bytes with simd-json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/json_parse.rs","lineNumber":36,"sourceCode":"        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\",\n        any(target_arch = \"x86_64\", target_arch = \"aarch64\")\n    )))]\n    {\n        serde_json::from_slice(bytes).map_err(|err| anyhow!(\"failed to decode json bytes: {err}\"))\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":48,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/json_parse.rs#L18-L48","documentation":"parse_json_bytes_in_place decodes a byte slice into T using simd-json (which mutates the buffer in place) when the linux-host-simd-json feature and matching target are active. Failures from simd_json::serde::from_slice are wrapped with this message. The caller must own a mutable buffer for this path.","triggerScenarios":"Malformed, truncated, or schema-mismatched JSON bytes are passed to parse_json_bytes_in_place on a simd-json-enabled build.","commonSituations":"Reading partially flushed network/file buffers; concatenated JSON values without a delimiter; T doesn't match the byte payload's structure.","solutions":["Log the wrapped simd-json error to identify the failure offset","Confirm the byte slice contains exactly one complete JSON value","Deserialize into serde_json::Value first to inspect the real shape if the schema is uncertain","Check for stray BOM or trailing bytes after the JSON value"],"exampleFix":"// before\nlet v: Event = parse_json_bytes_in_place(&mut buf)?;\n// after\nif buf.is_empty() { return Err(anyhow!(\"empty payload\")); }\nlet v: Event = parse_json_bytes_in_place(&mut buf)?;","handlingStrategy":"try-catch","validationCode":"fn looks_like_json_bytes(bytes: &[u8]) -> bool {\n    let t = bytes.iter().find(|b| !b.is_ascii_whitespace());\n    matches!(t, Some(b'{') | Some(b'['))\n}","typeGuard":null,"tryCatchPattern":"match parse_json_bytes_in_place::<Event>(&mut buf) {\n    Ok(v) => handle(v),\n    Err(e) if e.to_string().contains(\"simd-json\") => {\n        eprintln!(\"malformed payload: {e:#}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Read whole payloads, not partial socket/file chunks","Strip BOM and trailing whitespace before parsing","Version-check payloads if the schema can change","Keep simd and serde paths tested with the same fixtures"],"tags":["json","simd-json","bytes","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"}