From b605614e5b3dab828e4f33c300836deab421be34 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Fri, 28 Aug 2020 18:44:45 -0700 Subject: Use anyhow for error handling This patch changes our error handling approach from the ground up: instead of having a globally used Error enum that contains variants for all possible errors, we now use anyhow's Error type. This approach is more dynamic (and not statically typed), but it allows for more fine grained error messages and overall more user-friendly error reporting. Overall it also is a net simplification. While we have one dynamic cast now, in order to be able to handle erroneous password/PIN entries correctly, that is considered a reasonable compromise. --- src/main.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 27097c9..4f08d21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,11 +79,8 @@ use std::env; use std::ffi; use std::io; use std::process; -use std::result; -use crate::error::Error; - -type Result = result::Result; +use anyhow::Result; const NITROCLI_ADMIN_PIN: &str = "NITROCLI_ADMIN_PIN"; const NITROCLI_USER_PIN: &str = "NITROCLI_USER_PIN"; @@ -202,7 +199,7 @@ fn run<'ctx, 'io: 'ctx>(ctx: &'ctx mut RunCtx<'io>, args: Vec) -> i32 { match handle_arguments(ctx, args) { Ok(()) => 0, Err(err) => { - let _ = eprintln!(ctx, "{}", err); + let _ = eprintln!(ctx, "{:?}", err); 1 } } -- cgit v1.2.1