Skip to content

Commit

Permalink
Change error formatting to omit backtraces
Browse files Browse the repository at this point in the history
The format specifier we use for printing errors returned by the main
program will include a backtrace in the output -- if one is available.
That's not necessarily a feature that we need: the causal chain of
errors should be sufficient and end users are unlikely to have use for a
backtrace.
This change adjusts the format specifier so that we only print the chain
of errors, albeit in a slightly different format:
- Previously:
  > Failed to generate OTP
  >
  > Caused by:
  >     Command error: The given slot is not programmed

- New:
  > Failed to generate OTP: Command error: The given slot is not programmed
  • Loading branch information
d-e-s-o committed Apr 17, 2021
1 parent 49f518f commit 5c97919
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Unreleased
- Introduced extension support crate, `nitrocli-ext`
- Introduced `otp-cache` core extension
- Enabled usage of empty PWS slot fields
- Changed error reporting format to make up only a single line
- Added `NITROCLI_RESOLVED_USB_PATH` environment variable to be used by
extensions
- Allowed entering of `base32` encoded strings containing spaces
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn evaluate_err(err: anyhow::Error, stderr: &mut dyn io::Write) -> i32 {
if let Some(err) = err.root_cause().downcast_ref::<DirectExitError>() {
err.0
} else {
let _ = writeln!(stderr, "{:?}", err);
let _ = writeln!(stderr, "{:#}", err);
1
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/tests/otp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ use super::*;

use crate::args;

#[test_device]
fn error_format(model: nitrokey::Model) {
let (rc, out, err) = Nitrocli::new().model(model).run(&["otp", "get", "32"]);

assert_ne!(rc, 0);
assert_eq!(out, b"", "{}", String::from_utf8_lossy(&out));
assert_eq!(
err,
b"Failed to generate OTP: Library error: The given slot is invalid\n"
);
}

#[test_device]
fn set_invalid_slot_raw(model: nitrokey::Model) {
let (rc, out, err) = Nitrocli::new()
Expand Down

0 comments on commit 5c97919

Please sign in to comment.