rust-lang/cargo · error · AlreadyPrintedError
no sessions found{context}
Error message
no sessions found{context} What it means
`cargo report rebuilds` (an experimental -Z build-analysis feature) reads JSON build logs from the cargo home / target dir. If find_log_file returns None (no log file for the workspace or the given --id), it prints a 'no sessions found' report and bails at rebuilds.rs:63. The note tells you to enable -Z build-analysis to start producing logs.
Source
Thrown at src/ops/cargo_report/rebuilds.rs:63
} else {
String::new()
};
let (title, note) = if let Some(id) = &opts.id {
(
format!("session `{id}` not found{context}"),
"run `cargo report sessions` to list available sessions",
)
} else {
(
format!("no sessions found{context}"),
"run command with `-Z build-analysis` to generate log files",
)
};
let report = [Level::ERROR
.primary_title(title)
.element(Level::NOTE.message(note))];
gctx.shell().print_report(&report, false)?;
return Err(AlreadyPrintedError::new(anyhow::anyhow!("")).into());
};
let ctx = prepare_context(&log)
.with_context(|| format!("failed to analyze log at `{}`", log.display()))?;
let ws_root = ws.map(|ws| ws.root()).unwrap_or(gctx.cwd());
display_report(gctx, ctx, &run_id, ws_root)?;
Ok(())
}
struct Context {
root_rebuilds: Vec<RootRebuild>,
units: HashMap<UnitIndex, UnitInfo>,
total_cached: usize,
total_new: usize,
total_rebuilt: usize,
}View on GitHub (pinned to 0e07a15537)
Solutions
- Run a build with the feature enabled, e.g. `cargo build -Z build-analysis`, then re-run the report.
- If you passed --id, list valid sessions first with `cargo report sessions`.
- Confirm you are on a nightly toolchain that supports -Z build-analysis.
Example fix
# before $ cargo report rebuilds error: no sessions found # after $ cargo +nightly build -Z build-analysis $ cargo +nightly report rebuilds
Defensive patterns
Strategy: validation
Validate before calling
# Only report if at least one build-analysis log exists:
log_dir="${CARGO_TARGET_DIR:-target}/build-analysis"
if [ ! -d "$log_dir" ] || [ -z "$(ls -A "$log_dir" 2>/dev/null)" ]; then
echo "no sessions; run: cargo +nightly build -Z build-analysis" >&2
exit 1
fi
cargo report rebuilds Prevention
- Always build with `-Z build-analysis` before expecting report data.
- Use a nightly toolchain for build-analysis features.
- Run `cargo report sessions` first to confirm data exists.
When it happens
Trigger: Running `cargo report rebuilds` (or with `--id X`) without ever having built with `-Z build-analysis`, or after logs were garbage-collected.
Common situations: Exploring the build-analysis reporting before enabling the feature; pointing --id at a non-existent session; logs pruned by an older cargo.
Related errors
- no sessions found{context}
- no sessions found{context}
- no timing data found in log
- not implemented
- running the file `{cmd}` requires `-Zscript`
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/da95c2fa7b9ed63f.json.
Report an issue: GitHub.