mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Pretty-print errors
This commit is contained in:
parent
02c8c0af00
commit
84ebc0039e
2 changed files with 17 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::process::{ExitCode, Termination};
|
||||
|
||||
use log::warn;
|
||||
use miette::Diagnostic;
|
||||
use miette::{Report, Diagnostic};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Errors emitted by the library portion of cargo-binstall.
|
||||
|
@ -182,12 +182,13 @@ impl BinstallError {
|
|||
|
||||
impl Termination for BinstallError {
|
||||
fn report(self) -> ExitCode {
|
||||
let code = self.exit_code();
|
||||
if let BinstallError::UserAbort = self {
|
||||
warn!("Installation cancelled");
|
||||
} else {
|
||||
eprintln!("{self:?}");
|
||||
eprintln!("{:?}", Report::new(self));
|
||||
}
|
||||
|
||||
self.exit_code()
|
||||
code
|
||||
}
|
||||
}
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -90,11 +90,15 @@ impl Termination for MainExit {
|
|||
fn report(self) -> ExitCode {
|
||||
match self {
|
||||
Self::Success(spent) => {
|
||||
info!("Installation complete! [{spent:?}]");
|
||||
info!("Installation completed in {spent:?}");
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Self::Error(err) => err.report(),
|
||||
Self::Error(err) => {
|
||||
error!("Fatal error:");
|
||||
err.report()
|
||||
}
|
||||
Self::Report(err) => {
|
||||
error!("Fatal error:");
|
||||
eprintln!("{err:?}");
|
||||
ExitCode::from(16)
|
||||
}
|
||||
|
@ -112,14 +116,13 @@ fn main() -> MainExit {
|
|||
let done = start.elapsed();
|
||||
debug!("run time: {done:?}");
|
||||
|
||||
if let Err(err) = result {
|
||||
match err.downcast::<BinstallError>() {
|
||||
Ok(liberr) => MainExit::Error(liberr),
|
||||
Err(binerr) => MainExit::Report(binerr),
|
||||
}
|
||||
} else {
|
||||
MainExit::Success(done)
|
||||
}
|
||||
result
|
||||
.map(|_| MainExit::Success(done))
|
||||
.unwrap_or_else(|err| {
|
||||
err.downcast::<BinstallError>()
|
||||
.map(MainExit::Error)
|
||||
.unwrap_or_else(MainExit::Report)
|
||||
})
|
||||
}
|
||||
|
||||
async fn entry() -> Result<()> {
|
||||
|
|
Loading…
Add table
Reference in a new issue