mirror of
https://codeberg.org/icewind/evdev-shortcut.git
synced 2026-06-03 10:04:11 +02:00
improve error
This commit is contained in:
parent
f08f0e568e
commit
b3c36dbdf5
2 changed files with 16 additions and 4 deletions
17
src/lib.rs
17
src/lib.rs
|
|
@ -55,18 +55,29 @@ mod listener;
|
||||||
pub use listener::ShortcutListener;
|
pub use listener::ShortcutListener;
|
||||||
|
|
||||||
/// Error emitted when an input device can't be opened
|
/// Error emitted when an input device can't be opened
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct DeviceOpenError {
|
pub struct DeviceOpenError {
|
||||||
pub device: PathBuf,
|
pub device: PathBuf,
|
||||||
|
pub error: std::io::Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for DeviceOpenError {
|
impl Display for DeviceOpenError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "Failed to open device {:?}", self.device)
|
write!(
|
||||||
|
f,
|
||||||
|
"Failed to open device {}: {:#}",
|
||||||
|
self.device.display(),
|
||||||
|
self.error
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for DeviceOpenError {}
|
impl std::error::Error for DeviceOpenError {
|
||||||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
Some(&self.error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Modifier key for shortcuts
|
/// Modifier key for shortcuts
|
||||||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Display, FromStr)]
|
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Display, FromStr)]
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,9 @@ impl ShortcutListener {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let res = Device::open(path).map_err(|_| DeviceOpenError {
|
let res = Device::open(path).map_err(|error| DeviceOpenError {
|
||||||
device: path.into(),
|
device: path.into(),
|
||||||
|
error,
|
||||||
});
|
});
|
||||||
debug!(device = ?path, success = res.is_ok(), "opening input device");
|
debug!(device = ?path, success = res.is_ok(), "opening input device");
|
||||||
res
|
res
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue