{"id":"da95c2fa7b9ed63f","repo":"rust-lang/cargo","slug":"no-sessions-found-context","errorCode":null,"errorMessage":"no sessions found{context}","messagePattern":"no sessions found(.+?)","errorType":"exception","errorClass":"AlreadyPrintedError","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_report/rebuilds.rs","lineNumber":63,"sourceCode":"        } else {\n            String::new()\n        };\n        let (title, note) = if let Some(id) = &opts.id {\n            (\n                format!(\"session `{id}` not found{context}\"),\n                \"run `cargo report sessions` to list available sessions\",\n            )\n        } else {\n            (\n                format!(\"no sessions found{context}\"),\n                \"run command with `-Z build-analysis` to generate log files\",\n            )\n        };\n        let report = [Level::ERROR\n            .primary_title(title)\n            .element(Level::NOTE.message(note))];\n        gctx.shell().print_report(&report, false)?;\n        return Err(AlreadyPrintedError::new(anyhow::anyhow!(\"\")).into());\n    };\n\n    let ctx = prepare_context(&log)\n        .with_context(|| format!(\"failed to analyze log at `{}`\", log.display()))?;\n    let ws_root = ws.map(|ws| ws.root()).unwrap_or(gctx.cwd());\n\n    display_report(gctx, ctx, &run_id, ws_root)?;\n\n    Ok(())\n}\n\nstruct Context {\n    root_rebuilds: Vec<RootRebuild>,\n    units: HashMap<UnitIndex, UnitInfo>,\n    total_cached: usize,\n    total_new: usize,\n    total_rebuilt: usize,\n}","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_report/rebuilds.rs#L45-L81","documentation":"`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.","triggerScenarios":"Running `cargo report rebuilds` (or with `--id X`) without ever having built with `-Z build-analysis`, or after logs were garbage-collected.","commonSituations":"Exploring the build-analysis reporting before enabling the feature; pointing --id at a non-existent session; logs pruned by an older cargo.","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."],"exampleFix":"# before\n$ cargo report rebuilds\nerror: no sessions found\n\n# after\n$ cargo +nightly build -Z build-analysis\n$ cargo +nightly report rebuilds","handlingStrategy":"validation","validationCode":"# Only report if at least one build-analysis log exists:\nlog_dir=\"${CARGO_TARGET_DIR:-target}/build-analysis\"\nif [ ! -d \"$log_dir\" ] || [ -z \"$(ls -A \"$log_dir\" 2>/dev/null)\" ]; then\n  echo \"no sessions; run: cargo +nightly build -Z build-analysis\" >&2\n  exit 1\nfi\ncargo report rebuilds","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["report","build-analysis","experimental","nightly"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}