Skip to content

Commit

Permalink
chore: improve error message to suggest --project-manifest (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoIeni authored Mar 10, 2024
1 parent 8ed610e commit 4680821
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions crates/cargo_utils/src/workspace_members.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::Context;
use cargo_metadata::{Metadata, Package};
use std::path::Path;

pub fn get_manifest_metadata(manifest_path: &Path) -> anyhow::Result<cargo_metadata::Metadata> {
pub fn get_manifest_metadata(
manifest_path: &Path,
) -> Result<cargo_metadata::Metadata, cargo_metadata::Error> {
cargo_metadata::MetadataCommand::new()
.no_deps()
.manifest_path(manifest_path)
.exec()
.with_context(|| format!("invalid manifest {manifest_path:?}"))
}

/// Lookup all members of the current workspace
Expand Down
11 changes: 10 additions & 1 deletion crates/release_plz/src/args/repo_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ pub trait RepoCommand {
}

fn cargo_metadata(&self) -> anyhow::Result<cargo_metadata::Metadata> {
cargo_utils::get_manifest_metadata(&self.project_manifest())
let manifest = &self.project_manifest();
cargo_utils::get_manifest_metadata(manifest).map_err(|e| match e {
cargo_metadata::Error::CargoMetadata { stderr } => {
let stderr = stderr.trim();
anyhow::anyhow!("{stderr}. Use --project-manifest to specify the path to the manifest file if it's not in the current directory.")
}
_ => {
anyhow::anyhow!(e)
}
})
}

fn get_repo_url(&self, config: &Config) -> anyhow::Result<RepoUrl> {
Expand Down

0 comments on commit 4680821

Please sign in to comment.