From cb29c89424dc5a5dc0ee5c8a66e93b6592ebeb95 Mon Sep 17 00:00:00 2001 From: konsti Date: Mon, 16 Oct 2023 04:15:10 +0200 Subject: [PATCH] Better error reporting (#95) The main change is to print the whole error chain. We can combine this with adding `.context` to distinct phases to be able to locate crashes without having to use a debugger. --- crates/puffin-cli/src/commands/sync.rs | 5 +++-- crates/puffin-cli/src/main.rs | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/puffin-cli/src/commands/sync.rs b/crates/puffin-cli/src/commands/sync.rs index 45e270560..9e94c1339 100644 --- a/crates/puffin-cli/src/commands/sync.rs +++ b/crates/puffin-cli/src/commands/sync.rs @@ -1,7 +1,7 @@ use std::fmt::Write; use std::path::Path; -use anyhow::Result; +use anyhow::{Context, Result}; use bitflags::bitflags; use colored::Colorize; use itertools::{Either, Itertools}; @@ -206,7 +206,8 @@ pub(crate) async fn sync( let unzips = unzipper .download(downloads, cache.unwrap_or(staging.path())) - .await?; + .await + .context("Failed to download and unpack wheels")?; let s = if unzips.len() == 1 { "" } else { "s" }; writeln!( diff --git a/crates/puffin-cli/src/main.rs b/crates/puffin-cli/src/main.rs index f6eb5930c..47c22e830 100644 --- a/crates/puffin-cli/src/main.rs +++ b/crates/puffin-cli/src/main.rs @@ -159,7 +159,11 @@ async fn main() -> ExitCode { Err(err) => { #[allow(clippy::print_stderr)] { - eprintln!("{}: {}", "error".red().bold(), err); + let mut causes = err.chain(); + eprintln!("{}: {}", "error".red().bold(), causes.next().unwrap()); + for err in causes { + eprintln!(" {}: {}", "Caused by".red().bold(), err); + } } ExitStatus::Error.into() }