rtk-ai/rtk · error · anyhow::Error

Failed to parse binlog at

Error message

Failed to parse binlog at {}: empty file

What it means

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.

Solutions

  1. Re-run the build with binlog enabled (dotnet build -bl:build.binlog) so a real, non-empty binlog is generated.
  2. Check the file size before analysis (e.g. `ls -l build.binlog` or std::fs::metadata) and treat 0-byte files as missing input.
  3. If the file comes from CI, verify the artifact upload/download step preserved bytes and was not uploaded before the build finished.
  4. Regenerate the binlog with the same MSBuild version if the producing process was interrupted; ensure disk space is available.

Example fix

// before
rtk dotnet test --binlog artifacts/test.binlog  // file is 0 bytes
// after
if [ -s artifacts/test.binlog ]; then rtk dotnet test --binlog artifacts/test.binlog; else dotnet test -bl:artifacts/test.binlog; fi
Defensive patterns

Strategy: validation

Validate before calling

let meta = std::fs::metadata("build.binlog")?;
if meta.len() == 0 {
    // regenerate: dotnet build -bl:build.binlog
    bail!("binlog is empty (0 bytes); rebuild with -bl to regenerate");
}

Type guard

fn is_usable_binlog(path: &Path) -> bool {
    std::fs::metadata(path).map(|m| m.len() > 0).unwrap_or(false)
}

Try / catch

match rtk_dotnet_build(binlog) {
    Err(e) if e.to_string().contains("empty file") => regenerate_binlog_and_retry(),
    Err(e) => return Err(e),
    Ok(v) => Ok(v),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/a75d843fa110b9b8. Report an issue: GitHub.

Appendix: source

Thrown at src/cmds/dotnet/binlog.rs:303

    project_files: HashSet<String>,
    errors: Vec<BinlogIssue>,
    warnings: Vec<BinlogIssue>,
    build_succeeded: Option<bool>,
    build_started_ticks: Option<i64>,
    build_finished_ticks: Option<i64>,
}

#[derive(Default)]
struct ParsedEventFields {
    message: Option<String>,
    timestamp_ticks: Option<i64>,
}

fn parse_events_from_binlog(path: &Path) -> Result<ParsedBinlog> {
    let bytes = std::fs::read(path)
        .with_context(|| format!("Failed to read binlog at {}", path.display()))?;
    if bytes.is_empty() {
        anyhow::bail!("Failed to parse binlog at {}: empty file", path.display());
    }

    let mut decoder = GzDecoder::new(bytes.as_slice());
    let mut payload = Vec::new();
    decoder.read_to_end(&mut payload).with_context(|| {
        format!(
            "Failed to parse binlog at {}: gzip decode failed",
            path.display()
        )
    })?;

    let mut reader = BinReader::new(&payload);
    let file_format_version = reader
        .read_i32_le()
        .context("binlog header missing file format version")?;
    let _minimum_reader_version = reader
        .read_i32_le()
        .context("binlog header missing minimum reader version")?;

View on GitHub (pinned to 0924356b4c)