{"record":{"id":"a75d843fa110b9b8","repo":"rtk-ai/rtk","slug":"failed-to-parse-binlog-at-empty-file","errorCode":null,"errorMessage":"Failed to parse binlog at {}: empty file","messagePattern":"Failed to parse binlog at (.+?): empty file","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cmds/dotnet/binlog.rs","lineNumber":303,"sourceCode":"    project_files: HashSet<String>,\n    errors: Vec<BinlogIssue>,\n    warnings: Vec<BinlogIssue>,\n    build_succeeded: Option<bool>,\n    build_started_ticks: Option<i64>,\n    build_finished_ticks: Option<i64>,\n}\n\n#[derive(Default)]\nstruct ParsedEventFields {\n    message: Option<String>,\n    timestamp_ticks: Option<i64>,\n}\n\nfn parse_events_from_binlog(path: &Path) -> Result<ParsedBinlog> {\n    let bytes = std::fs::read(path)\n        .with_context(|| format!(\"Failed to read binlog at {}\", path.display()))?;\n    if bytes.is_empty() {\n        anyhow::bail!(\"Failed to parse binlog at {}: empty file\", path.display());\n    }\n\n    let mut decoder = GzDecoder::new(bytes.as_slice());\n    let mut payload = Vec::new();\n    decoder.read_to_end(&mut payload).with_context(|| {\n        format!(\n            \"Failed to parse binlog at {}: gzip decode failed\",\n            path.display()\n        )\n    })?;\n\n    let mut reader = BinReader::new(&payload);\n    let file_format_version = reader\n        .read_i32_le()\n        .context(\"binlog header missing file format version\")?;\n    let _minimum_reader_version = reader\n        .read_i32_le()\n        .context(\"binlog header missing minimum reader version\")?;","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/dotnet/binlog.rs#L285-L321","documentation":"This error is raised by parse_events_from_binlog when the .binlog file at the given path exists but has zero bytes. A binlog is MSBuild's binary build log, which must contain a gzip header and at least a 2-int version header; an empty file cannot contain any valid binlog. The parser bails early with the file path included so the developer can locate the corrupt/empty artifact.","triggerScenarios":"Calling rtk dotnet build/test/restore with a --binlog path (or having MSBuild produce one) where the .binlog file is 0 bytes, then parse_events_from_binlog reads it via std::fs::read and takes the bytes.is_empty() branch.","commonSituations":"The build crashed or was killed before MSBuild flushed the binlog; a failed `dotnet build -bl` run created a placeholder file; a CI artifact download truncated the file to 0 bytes; a test fixture uses a touched empty file as a fake binlog.","solutions":["Re-run the build with binlog enabled (dotnet build -bl:build.binlog) so a real, non-empty binlog is generated.","Check the file size before analysis (e.g. `ls -l build.binlog` or std::fs::metadata) and treat 0-byte files as missing input.","If the file comes from CI, verify the artifact upload/download step preserved bytes and was not uploaded before the build finished.","Regenerate the binlog with the same MSBuild version if the producing process was interrupted; ensure disk space is available."],"exampleFix":"// before\nrtk dotnet test --binlog artifacts/test.binlog  // file is 0 bytes\n// after\nif [ -s artifacts/test.binlog ]; then rtk dotnet test --binlog artifacts/test.binlog; else dotnet test -bl:artifacts/test.binlog; fi","handlingStrategy":"validation","validationCode":"let meta = std::fs::metadata(\"build.binlog\")?;\nif meta.len() == 0 {\n    // regenerate: dotnet build -bl:build.binlog\n    bail!(\"binlog is empty (0 bytes); rebuild with -bl to regenerate\");\n}","typeGuard":"fn is_usable_binlog(path: &Path) -> bool {\n    std::fs::metadata(path).map(|m| m.len() > 0).unwrap_or(false)\n}","tryCatchPattern":"match rtk_dotnet_build(binlog) {\n    Err(e) if e.to_string().contains(\"empty file\") => regenerate_binlog_and_retry(),\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Check file size > 0 before feeding any .binlog to the parser","Use -bl:file.binlog with a full path and confirm the build exits successfully before consuming the log","In CI, upload binlog artifacts only after a build step completes (or upload-if-failed with size checks)","Never commit placeholder/touched .binlog files as fixtures; generate real ones"],"tags":["dotnet","binlog","empty-file","msbuild"],"backgroundTag":"empty-required-field","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"}