rust-lang/cargo · error · AlreadyPrintedError

no sessions found{context}

Error message

no sessions found{context}

What it means

`cargo report sessions` lists build-analysis sessions from log files on disk. If list_log_files yields none for the (workspace's) run id set, it emits 'no sessions found' and bails at sessions.rs:46. Sessions are only created when builds run with -Z build-analysis.

Source

Thrown at src/ops/cargo_report/sessions.rs:46

                .unwrap_or(true)
        })
        .take(opts.limit + 1)
        .collect();

    if sessions.is_empty() {
        let context = if let Some(ws) = ws {
            format!(" for workspace at `{}`", ws.root().display())
        } else {
            String::new()
        };
        let title = format!("no sessions found{context}");
        let note = "run build commands 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(crate::AlreadyPrintedError::new(anyhow::anyhow!("")).into());
    }

    let truncated = sessions.len() > opts.limit;
    let display_count = opts.limit.min(sessions.len());

    let mut shell = gctx.shell();
    let stderr = shell.err();

    if let Some(ws) = ws {
        writeln!(
            stderr,
            "Session IDs for `{}` (most recent first):",
            ws.root().display(),
        )?;
    } else {
        writeln!(stderr, "Session IDs (most recent first):",)?
    };
    writeln!(stderr)?;

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Run any build command with `-Z build-analysis` (e.g. `cargo +nightly build -Z build-analysis`) to create a session.
  2. Verify the log directory under the cargo target/home is writable and not cleaned by an external process.
  3. Use a nightly toolchain; the flag is unstable.

Example fix

# before
$ cargo report sessions
error: no sessions found

# after
$ cargo +nightly build -Z build-analysis
$ cargo +nightly report sessions
Defensive patterns

Strategy: validation

Validate before calling

# Check for any session log before listing sessions:
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 sessions

Prevention

When it happens

Trigger: Running `cargo report sessions` before any build has been executed with `-Z build-analysis` enabled.

Common situations: First use of the build-analysis subsystem; logs deleted; running on stable where the flag is unavailable.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/82d9e9eadbe74510.json. Report an issue: GitHub.