Skip to content

Commit 8452eb3

Browse files
Jan Rüthjanrueth
Jan Rüth
authored andcommitted
Add error context to functions executed during button press
Errors during executing button press action are hard to debug as its unclear what exactly is causing them. This change adds a context to all executed functions.
1 parent cff1bbb commit 8452eb3

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

es2button/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "es2button"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["Jan Rüth <es2button@djiehmail.com>"]
55
edition = "2021"
66
license = "MIT"

es2button/src/listener.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ impl<'a> Listener<'a> {
7979
.get_bool_value_for_key(es2command::ESKEY_CARD_SCANNING)
8080
}
8181

82-
fn handle_button_press(&self, button: u8) -> Result<(), ESError> {
82+
fn handle_button_press(&self, button: u8) -> Result<(), anyhow::Error> {
8383
debug!("Button pressed: {}", button);
8484

8585
trace!("Checking scanner document state");
86-
let doc_present = self.is_document_loaded()?;
87-
let card_scanning = self.is_card_scanning()?;
86+
let doc_present = self
87+
.is_document_loaded()
88+
.context("checking document status")?;
89+
let card_scanning = self.is_card_scanning().context("checking card scanning")?;
8890

8991
trace!("Disconnecting from scanner");
90-
self.scanner.close()?;
92+
self.scanner.close().context("closing scanner")?;
9193

9294
trace!("Spawning process");
9395
let output = Command::new(&self.program)
@@ -107,7 +109,7 @@ impl<'a> Listener<'a> {
107109
.env("ES2_DEV_VID", format!("{:03}", self.device.vid))
108110
.env("ES2_DEV_PID", format!("{:03}", self.device.pid))
109111
.output()
110-
.expect("failed executing program");
112+
.expect("program execution failed"); // do not error here as we can't open the scanner otherwise, user needs to fix their script
111113

112114
info!("Script status: {}", output.status);
113115
info!("Script stdout:");
@@ -117,7 +119,7 @@ impl<'a> Listener<'a> {
117119
info!("Resuming from script");
118120

119121
trace!("Reopening connection to scanner");
120-
self.scanner.open()
122+
self.scanner.open().context("opening scanner")
121123
}
122124
}
123125

@@ -135,7 +137,7 @@ impl<'a> es2command::ScanDelegate for Listener<'a> {
135137

136138
fn did_press_button(&self, button: u8) {
137139
if let Err(err) = self.handle_button_press(button) {
138-
error!("failed handling button press: {}", err);
140+
error!("failed handling button press: {:#}", err);
139141
}
140142
}
141143

0 commit comments

Comments
 (0)