Skip to content

fix: improve error message when unable to parse walltime results #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/cargo-codspeed/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,16 @@ pub fn run_benches(
}

fn aggregate_raw_walltime_data(workspace_root: &Path) -> Result<()> {
let results = WalltimeResults::collect_walltime_results(workspace_root)?;
let results = WalltimeResults::collect_walltime_results(workspace_root)
.with_context(|| {
format!(
"Failed to collect walltime results. This may be due to version incompatibility. \
Ensure that your compat layer (codspeed-criterion-compat, codspeed-bencher-compat, or codspeed-divan-compat) \
has the same major version as cargo-codspeed (currently v{}).",
env!("CARGO_PKG_VERSION")
)
})?;

if results.benchmarks().is_empty() {
eprintln!("No walltime benchmarks found");
return Ok(());
Expand Down
27 changes: 13 additions & 14 deletions crates/codspeed/src/walltime_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ impl WalltimeBenchmark {
}

fn dump_to_results(&self, workspace_root: &Path, scope: &str) {
let output_dir =
WalltimeResults::result_dir_from_workspace_root(workspace_root).join(scope);
let output_dir = result_dir_from_workspace_root(workspace_root).join(scope);
std::fs::create_dir_all(&output_dir).unwrap();
let bench_id = uuid::Uuid::new_v4().to_string();
let output_path = output_dir.join(format!("{}.json", bench_id));
Expand Down Expand Up @@ -233,7 +232,7 @@ impl WalltimeResults {
// retrieve data from `{workspace_root}/target/codspeed/raw_results/{scope}/*.json
let benchmarks = glob::glob(&format!(
"{}/**/*.json",
WalltimeResults::result_dir_from_workspace_root(workspace_root)
result_dir_from_workspace_root(workspace_root)
.to_str()
.unwrap(),
))?
Expand All @@ -258,28 +257,28 @@ impl WalltimeResults {
}

pub fn clear(workspace_root: &Path) -> Result<()> {
let raw_results_dir = WalltimeResults::result_dir_from_workspace_root(workspace_root);
let raw_results_dir = result_dir_from_workspace_root(workspace_root);
std::fs::remove_dir_all(&raw_results_dir).ok(); // ignore errors when the directory does not exist
std::fs::create_dir_all(&raw_results_dir)
.context("Failed to create raw_results directory")?;
Ok(())
}

// FIXME: This assumes that the cargo target dir is `target`, and duplicates information with
// `cargo-codspeed::helpers::get_codspeed_target_dir`
fn result_dir_from_workspace_root(workspace_root: &Path) -> PathBuf {
workspace_root
.join("target")
.join("codspeed")
.join("walltime")
.join("raw_results")
}

pub fn benchmarks(&self) -> &[WalltimeBenchmark] {
&self.benchmarks
}
}

// FIXME: This assumes that the cargo target dir is `target`, and duplicates information with
// `cargo-codspeed::helpers::get_codspeed_target_dir`
fn result_dir_from_workspace_root(workspace_root: &Path) -> PathBuf {
workspace_root
.join("target")
.join("codspeed")
.join("walltime")
.join("raw_results")
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down