From 27a0fd23d8a9d99867d16b19b597bc6ba9d24748 Mon Sep 17 00:00:00 2001 From: lf- Date: Thu, 31 Dec 2020 04:42:59 -0800 Subject: add working dir to cargo metadata fail messages --- crates/project_model/src/cargo_workspace.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crates/project_model') diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index bb3b6f2ef..b991b59a6 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs @@ -1,6 +1,7 @@ //! FIXME: write short doc here use std::{ + convert::TryInto, ffi::OsStr, ops, path::{Path, PathBuf}, @@ -196,8 +197,23 @@ impl CargoWorkspace { if let Some(target) = target { meta.other_options(vec![String::from("--filter-platform"), target]); } + let mut meta = meta.exec().with_context(|| { - format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display()) + let cwd: Option = + std::env::current_dir().ok().and_then(|p| p.try_into().ok()); + + let workdir = cargo_toml + .parent() + .map(|p| p.to_path_buf()) + .or(cwd) + .map(|dir| dir.to_string_lossy().to_string()) + .unwrap_or_else(|| "".into()); + + format!( + "Failed to run `cargo metadata --manifest-path {}` in `{}`", + cargo_toml.display(), + workdir + ) })?; let mut out_dir_by_id = FxHashMap::default(); -- cgit v1.2.3