win_event_hook/errors.rs
1use rayon::ThreadPoolBuildError;
2use thiserror::Error;
3
4use crate::config::Config;
5
6/// `win_event_hook` library error type.
7#[derive(Error, Debug)]
8pub enum Error {
9 /// Indicates an event with a given id is not known.
10 #[error("No known event '{0}'")]
11 InvalidEvent(u32),
12 /// Indicates an event with a given id falls outside the configured range.
13 #[error("Event '{event}' falls outside valid range [{min}, {max}]")]
14 InvalidRangedEvent { event: u32, min: u32, max: u32 },
15 /// Indicates a config instance was determined to be invalid.
16 #[error("Config '{0:?}' is not valid")]
17 InvalidConfig(Config),
18 /// Indicates an installation failure.
19 /// See [Microsoft Documentation](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwineventhook#return-value)
20 /// for more information.
21 #[error("Failed to install WinEventHook")]
22 Installation,
23 /// Indicates an installation failure due to an underlying threadpool issue.
24 #[error("Failed to allocate threadpool")]
25 Threadpool(#[from] ThreadPoolBuildError),
26 /// Indicates an uninstallation failure.
27 /// See [Microsoft Documentation](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-unhookwinevent#return-value)
28 /// for more information.
29 #[error("Failed to uninstall WinEventHook")]
30 Uninstallation,
31 /// Indicates an uninstallation failure due to an underlying event loop issue.
32 #[error("Failed to terminate eventloop")]
33 EventLoop(#[from] windows::core::Error),
34 /// Indicates an uninstallation failure due to the hook already being uninstalled.
35 #[error("Failed to uninstall WinEventHook, already uninstalled")]
36 AlreadyUninstalled,
37}
38
39/// `win_event_hook` library result type.
40pub type Result<T> = std::result::Result<T, Error>;