{"record":{"id":"bcdac1fa21cdb4b2","repo":"rtk-ai/rtk","slug":"unexpected-end-of-stream","errorCode":null,"errorMessage":"unexpected end of stream","messagePattern":"unexpected end of stream","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cmds/dotnet/binlog.rs","lineNumber":580,"sourceCode":"    cursor: Cursor<&'a [u8]>,\n}\n\nimpl<'a> BinReader<'a> {\n    fn new(bytes: &'a [u8]) -> Self {\n        Self {\n            cursor: Cursor::new(bytes),\n        }\n    }\n\n    fn is_eof(&self) -> bool {\n        (self.cursor.position() as usize) >= self.cursor.get_ref().len()\n    }\n\n    fn read_exact(&mut self, len: usize) -> Result<&'a [u8]> {\n        let start = self.cursor.position() as usize;\n        let end = start.saturating_add(len);\n        if end > self.cursor.get_ref().len() {\n            anyhow::bail!(\"unexpected end of stream\");\n        }\n        self.cursor.set_position(end as u64);\n        Ok(&self.cursor.get_ref()[start..end])\n    }\n\n    fn skip(&mut self, len: usize) -> Result<()> {\n        let _ = self.read_exact(len)?;\n        Ok(())\n    }\n\n    fn read_u8(&mut self) -> Result<u8> {\n        Ok(self.read_exact(1)?[0])\n    }\n\n    fn read_bool(&mut self) -> Result<bool> {\n        Ok(self.read_u8()? != 0)\n    }\n","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/dotnet/binlog.rs#L562-L598","documentation":"This error is raised by the binlog reader's `read_exact` helper when a requested read of `len` bytes would extend past the end of the in-memory buffer (`end > cursor.get_ref().len()`). It means the .NET binary log (binlog) file is truncated or malformed: a record header promised more bytes than the file actually contains. The library throws instead of panicking or returning garbage bytes.","triggerScenarios":"Any of the reader helpers (`skip`, `read_u8`, `read_i32_le`, `read_i64_le`, `read_dotnet_string`) request bytes whose end offset exceeds the buffer length — e.g. a length-prefixed string whose declared length runs past EOF, a fixed-size integer near EOF, or a `skip` past the last byte.","commonSituations":"Corrupted or partially downloaded/truncated .binlog file; a file that is not actually a binlog being fed to the parser; a binlog produced by a newer .NET SDK with record formats the reader misinterprets, causing bogus length fields; reading a file that is still being written by a concurrent `dotnet build`.","solutions":["Verify the .binlog file is complete and uncorrupted (re-run `dotnet build -bl` to regenerate it); do not read a log while the build is still running.","Confirm the input actually is a Binary Log (magic bytes) before parsing; passing an arbitrary file here produces bogus lengths and immediate truncation errors.","Check reader/binlog format-version handling: if the file came from a newer .NET SDK, upgrade the tool so record headers are parsed with the correct offsets.","Wrap parsing in error handling that treats 'unexpected end of stream' as an input-validity problem and falls back to raw `dotnet` output rather than failing the whole command."],"exampleFix":"// before\nlet bytes = reader.read_exact(len as usize)?; // bails on truncated input\n\n// after\nlet bytes = match reader.read_exact(len as usize) {\n    Ok(b) => b,\n    Err(_) => return fallback_to_raw_dotnet(args), // rtk fallback pattern\n};","handlingStrategy":"fallback","validationCode":"let meta = std::fs::metadata(path)?;\nif meta.len() < 64 { bail!(\"file too small to be a binlog\"); }\nlet mut f = std::fs::File::open(path)?;\nlet mut magic = [0u8; 7];\nuse std::io::Read;\nf.read_exact(&mut magic)?; // fails fast if truncated\nif &magic != b\"!BinLog\" { bail!(\"not a binlog file\"); }","typeGuard":null,"tryCatchPattern":"match read_binlog_summary(path) {\n    Ok(summary) => summary,\n    Err(e) if e.to_string().contains(\"unexpected end of stream\") => {\n        eprintln!(\"binlog truncated/corrupt, falling back to raw output\");\n        passthrough_raw()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Never parse a .binlog while `dotnet build -bl` is still writing it; wait for the build to finish.","Validate the file's magic bytes and minimum size before parsing.","Keep the reader in sync with the .NET SDK versions that produce your logs.","Treat any stream-termination error as input corruption, not a code bug; log the file path and size."],"tags":["dotnet","binlog","parse-error","truncated-input"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}