rust-lang/cargo · error · AlreadyPrintedError

no sessions found{context}

Error message

no sessions found{context}

What it means

`cargo report timings` needs a build-analysis log to render timing reports. find_log_file returns None when no log exists for the workspace or the supplied --id, so timings.rs:79 bails with 'no sessions found'. Like the sibling commands, logs are produced only with -Z build-analysis.

Source

Thrown at src/ops/cargo_report/timings.rs:79

        } 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 reader = BufReader::new(File::open(&log)?);
    let iter = serde_json::Deserializer::from_reader(reader)
        .into_iter::<LogMessage>()
        .enumerate()
        .filter_map(|(idx, msg)| match msg {
            Ok(msg) => Some(msg),
            Err(e) => {
                tracing::warn!("failed to parse log message at index {idx}: {e}");
                None
            }
        });
    let ctx = prepare_context(iter, &run_id, true)
        .with_context(|| format!("failed to analyze log at `{}`", log.display()))?;

    // If we are in a workspace,
    // put timing reports in <target-dir>/cargo-timings/` as usual for easy access.

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Build first with analysis enabled: `cargo +nightly build -Z build-analysis`, then `cargo report timings`.
  2. Use `cargo report sessions` to discover valid --id values.
  3. For per-build HTML timing reports without the unstable flag, use `cargo build --timings` instead.

Example fix

# before
$ cargo report timings
error: no sessions found

# after
$ cargo +nightly build -Z build-analysis
$ cargo +nightly report timings
# (or, for stable per-build HTML timings:)
$ cargo build --timings
Defensive patterns

Strategy: validation

Validate before calling

# Verify a session log exists before reporting timings:
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 timings

Prevention

When it happens

Trigger: Running `cargo report timings` without a prior `-Z build-analysis` build, or with an --id that does not correspond to any stored session.

Common situations: Confusing `cargo report timings` with the stable `--timings` build flag; clean log dir; stale --id.

Related errors


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