rtk-ai/rtk · error · anyhow::Error
unexpected end of stream
Error message
unexpected end of stream
What it means
BinReader::read_exact attempts to take `len` bytes at the current cursor and the requested range extends past the end of the in-memory buffer. All primitive readers (skip, read_u8, read_i32_le, read_i64_le, read_dotnet_string) funnel through it, so any truncated read surfaces as this error.
Source
Thrown at src/cmds/dotnet/binlog.rs:580
cursor: Cursor<&'a [u8]>,
}
impl<'a> BinReader<'a> {
fn new(bytes: &'a [u8]) -> Self {
Self {
cursor: Cursor::new(bytes),
}
}
fn is_eof(&self) -> bool {
(self.cursor.position() as usize) >= self.cursor.get_ref().len()
}
fn read_exact(&mut self, len: usize) -> Result<&'a [u8]> {
let start = self.cursor.position() as usize;
let end = start.saturating_add(len);
if end > self.cursor.get_ref().len() {
anyhow::bail!("unexpected end of stream");
}
self.cursor.set_position(end as u64);
Ok(&self.cursor.get_ref()[start..end])
}
fn skip(&mut self, len: usize) -> Result<()> {
let _ = self.read_exact(len)?;
Ok(())
}
fn read_u8(&mut self) -> Result<u8> {
Ok(self.read_exact(1)?[0])
}
fn read_bool(&mut self) -> Result<bool> {
Ok(self.read_u8()? != 0)
}
View on GitHub (pinned to 36788f6bd4)
Solutions
- Regenerate the binlog — the current file is truncated or corrupt
- Verify expected file size vs actual (compare with CI artifact checksum)
- Confirm the file is a real binlog, not an arbitrary file passed by mistake
Defensive patterns
Strategy: try-catch
Try / catch
match parse_events_from_binlog(&path) {
Ok(b) => use_events(&b),
Err(e) if e.to_string().contains("unexpected end of stream") => {
eprintln!("binlog truncated; rerun the build to regenerate it");
}
Err(e) => return Err(e),
} Prevention
- Wait for build completion before consuming the binlog (file locks/completion markers)
- Verify artifact size/checksum after transfer
- Enable atomic file writes (write temp then rename) in your build scripts
When it happens
Trigger: Any decode step in parse_events_from_binlog whose declared length exceeds remaining bytes — a record/event/string length pointing beyond EOF, i.e. truncated or misaligned payload.
Common situations: Binlog truncated by crash/disk-full/interrupted copy; misaligned parse after corrupt data; passing a non-binlog file whose bytes don't match declared sizes.
Related errors
- negative record length: {}
- negative event length: {}
- invalid 7-bit encoded integer
- negative string length: {}
- Failed to parse binlog at {}: empty file
AI-assisted analysis of rtk-ai/rtk@36788f6bd4 (2026-09-03).
Data as JSON: /api/errors/bcdac1fa21cdb4b2.
Report an issue: GitHub.