xai-org/grok-build · error · io::Error
{}
Error message
{} What it means
JsonlHunkRecordWriter::write serializes each HunkRecord to JSON before appending a newline; if serde_json fails, the error is converted to io::ErrorKind::InvalidData. This is a programming/data error, not an I/O failure.
Source
Thrown at crates/codegen/xai-hunk-tracker/src/loc/mod.rs:266
let file = tokio::fs::OpenOptions::new()
.create(true)
.append(true)
.open(&self.path)
.await?;
self.file = Some(file);
}
// The `if` block above guarantees `self.file` is `Some` at this point.
Ok(self.file.as_mut().unwrap())
}
}
impl HunkRecordWriter for JsonlHunkRecordWriter {
async fn write(&mut self, record: &HunkRecord) -> std::io::Result<()> {
use tokio::io::AsyncWriteExt;
let file = self.ensure_open().await?;
let mut line = serde_json::to_string(record)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
line.push('\n');
file.write_all(line.as_bytes()).await?;
Ok(())
}
async fn flush(&mut self) -> std::io::Result<()> {
use tokio::io::AsyncWriteExt;
if let Some(file) = self.file.as_mut() {
file.flush().await?;
}
Ok(())
}
}
// ---------------------------------------------------------------------------
// LocAggregate (channel-based bridge to signals)
// ---------------------------------------------------------------------------View on GitHub (pinned to bc7f02eddd)
Solutions
- Read the underlying serde_json error (the io error's source) to locate the failing field
- Fix the offending field type or its Serialize implementation
- Use serde_json::to_value in a debug assertion to fail fast at record construction
Defensive patterns
Strategy: try-catch
Validate before calling
fn record_json_ok(r: &HunkRecord) -> bool {
serde_json::to_string(r).is_ok()
}
debug_assert!(record_json_ok(record)); Try / catch
if let Err(e) = writer.write(&record).await {
if e.kind() == std::io::ErrorKind::InvalidData {
eprintln!("record failed JSON serialization: {}", e);
}
return Err(e.into());
} Prevention
- Keep HunkRecord fields JSON-safe (no non-string map keys, no NaN)
- Add a round-trip test serde_json::from_str::<HunkRecord>(&serde_json::to_string(&r)?)
- Avoid custom Serialize impls that can return Err
When it happens
Trigger: Writing a HunkRecord whose fields cannot serialize to JSON (e.g. map keys that aren't strings, NaN in a float field when strict, or a custom Serialize impl that errors).
Common situations: Evolving HunkRecord with a non-JSON-safe field; passing records built from untrusted input with unexpected shapes; custom Serialize impls returning Err.
Related errors
- Compaction checkpoint file corrupt: {checkpoint_path}. Canno
- {}
- failed to build request: {e}
- response parse error: {e}
- failed to read {}: {e}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/fa2c6a749f25a017.
Report an issue: GitHub.