Skip to content
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

Display the causes of an error #931

Merged
merged 4 commits into from
Jan 31, 2023
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
7 changes: 6 additions & 1 deletion crates/build/src/crate_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ fn get_cargo_metadata(manifest_path: &ManifestPath) -> Result<(CargoMetadata, Pa
let metadata = cmd
.manifest_path(manifest_path.as_ref())
.exec()
.context("Error invoking `cargo metadata`")?;
.with_context(|| {
format!(
"Error invoking `cargo metadata` for {}",
manifest_path.as_ref().display()
)
})?;
let root_package_id = metadata
.resolve
.as_ref()
Expand Down
14 changes: 12 additions & 2 deletions crates/cargo-contract/src/cmd/extrinsics/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

use sp_runtime::DispatchError;
use std::fmt::Display;
use std::fmt::{
self,
Debug,
Display,
};

#[derive(serde::Serialize)]
pub enum ErrorVariant {
Expand Down Expand Up @@ -93,8 +97,14 @@ impl ErrorVariant {
}
}

impl Debug for ErrorVariant {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Self as Display>::fmt(self, f)
}
}

impl Display for ErrorVariant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ErrorVariant::Module(err) => {
f.write_fmt(format_args!(
Expand Down
8 changes: 4 additions & 4 deletions crates/cargo-contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use contract_build::{
OutputType,
};
use std::{
fmt::Display,
fmt::Debug,
path::PathBuf,
str::FromStr,
};
Expand Down Expand Up @@ -136,7 +136,7 @@ fn main() {
match exec(args.cmd) {
Ok(()) => {}
Err(err) => {
eprintln!("{err}");
eprintln!("{err:?}");
std::process::exit(1);
}
}
Expand Down Expand Up @@ -207,10 +207,10 @@ fn map_extrinsic_err(err: ErrorVariant, is_json: bool) -> Error {
}
}

fn format_err<E: Display>(err: E) -> Error {
fn format_err<E: Debug>(err: E) -> Error {
anyhow!(
"{} {}",
"ERROR:".bright_red().bold(),
format!("{err}").bright_red()
format!("{err:?}").bright_red()
)
}