Skip to content

Commit 1f0f934

Browse files
committed
fix: improve error message when unable to parse walltime results
1 parent 2979348 commit 1f0f934

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

crates/cargo-codspeed/src/run.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,16 @@ pub fn run_benches(
180180
}
181181

182182
fn aggregate_raw_walltime_data(workspace_root: &Path) -> Result<()> {
183-
let results = WalltimeResults::collect_walltime_results(workspace_root)?;
183+
let results = WalltimeResults::collect_walltime_results(workspace_root)
184+
.with_context(|| {
185+
format!(
186+
"Failed to collect walltime results. This may be due to version incompatibility. \
187+
Ensure that your compat layer (codspeed-criterion-compat, codspeed-bencher-compat, or codspeed-divan-compat) \
188+
has the same major version as cargo-codspeed (currently v{}).",
189+
env!("CARGO_PKG_VERSION")
190+
)
191+
})?;
192+
184193
if results.benchmarks().is_empty() {
185194
eprintln!("No walltime benchmarks found");
186195
return Ok(());

crates/codspeed/src/walltime_results.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ impl WalltimeBenchmark {
189189
}
190190

191191
fn dump_to_results(&self, workspace_root: &Path, scope: &str) {
192-
let output_dir =
193-
WalltimeResults::result_dir_from_workspace_root(workspace_root).join(scope);
192+
let output_dir = result_dir_from_workspace_root(workspace_root).join(scope);
194193
std::fs::create_dir_all(&output_dir).unwrap();
195194
let bench_id = uuid::Uuid::new_v4().to_string();
196195
let output_path = output_dir.join(format!("{}.json", bench_id));
@@ -233,7 +232,7 @@ impl WalltimeResults {
233232
// retrieve data from `{workspace_root}/target/codspeed/raw_results/{scope}/*.json
234233
let benchmarks = glob::glob(&format!(
235234
"{}/**/*.json",
236-
WalltimeResults::result_dir_from_workspace_root(workspace_root)
235+
result_dir_from_workspace_root(workspace_root)
237236
.to_str()
238237
.unwrap(),
239238
))?
@@ -258,28 +257,28 @@ impl WalltimeResults {
258257
}
259258

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

268-
// FIXME: This assumes that the cargo target dir is `target`, and duplicates information with
269-
// `cargo-codspeed::helpers::get_codspeed_target_dir`
270-
fn result_dir_from_workspace_root(workspace_root: &Path) -> PathBuf {
271-
workspace_root
272-
.join("target")
273-
.join("codspeed")
274-
.join("walltime")
275-
.join("raw_results")
276-
}
277-
278267
pub fn benchmarks(&self) -> &[WalltimeBenchmark] {
279268
&self.benchmarks
280269
}
281270
}
282271

272+
// FIXME: This assumes that the cargo target dir is `target`, and duplicates information with
273+
// `cargo-codspeed::helpers::get_codspeed_target_dir`
274+
fn result_dir_from_workspace_root(workspace_root: &Path) -> PathBuf {
275+
workspace_root
276+
.join("target")
277+
.join("codspeed")
278+
.join("walltime")
279+
.join("raw_results")
280+
}
281+
283282
#[cfg(test)]
284283
mod tests {
285284
use super::*;

0 commit comments

Comments
 (0)