nikivdev/code · error
failed to decode json line with simd-json: {err}
Error message
failed to decode json line with simd-json: {err} What it means
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).
Source
Thrown at src/json_parse.rs:14
use anyhow::{Result, anyhow};
use serde::de::DeserializeOwned;
#[inline]
pub fn parse_json_line<T: DeserializeOwned>(line: &str) -> Result<T> {
#[cfg(all(
feature = "linux-host-simd-json",
target_os = "linux",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
{
let mut buf = line.as_bytes().to_vec();
return simd_json::serde::from_slice(&mut buf)
.map_err(|err| anyhow!("failed to decode json line with simd-json: {err}"));
}
#[cfg(not(all(
feature = "linux-host-simd-json",
target_os = "linux",
any(target_arch = "x86_64", target_arch = "aarch64")
)))]
{
serde_json::from_str(line).map_err(|err| anyhow!("failed to decode json line: {err}"))
}
}
#[inline]
pub fn parse_json_bytes_in_place<T: DeserializeOwned>(bytes: &mut [u8]) -> Result<T> {
#[cfg(all(
feature = "linux-host-simd-json",
target_os = "linux",
any(target_arch = "x86_64", target_arch = "aarch64")View on GitHub (pinned to a747e741ae)
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
Example fix
// before
let v: Event = parse_json_line(line)?; // panics-equivalent on blank line
// after
if line.trim().is_empty() { return Ok(None); }
let v: Event = parse_json_line(line)?; Defensive patterns
Strategy: try-catch
Validate before calling
fn is_plausible_json(line: &str) -> bool {
let t = line.trim();
!t.is_empty() && (t.starts_with('{') || t.starts_with('['))
} Type guard
fn looks_like_json_object(s: &str) -> bool {
s.trim_start().starts_with('{') && s.trim_end().ends_with('}')
} Try / catch
match parse_json_line::<Event>(line) {
Ok(v) => handle(v),
Err(e) if e.to_string().contains("simd-json") => {
eprintln!("skipping malformed line: {e:#}"); // or buffer for retry
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Partially written or truncated log lines; the stream emits non-JSON lines (plain text, empty line); schema drift between producer and consumer struct.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to decode json bytes with simd-json: {err}
- failed to decode json line: {err}
- failed to decode json bytes: {err}
- 'codanna mcp get_index_info' failed: {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/d41bfe23bce9bde7.
Report an issue: GitHub.