window_enumerator/
errors.rs1use std::fmt;
2
3#[derive(Debug)]
5pub enum WindowError {
6 InvalidSelectionFormat,
10
11 InvalidPositionSortFormat,
15
16 InvalidRange,
20
21 InvalidIndex,
23
24 InvalidSortOrder,
28
29 WindowsApiError(u32),
33
34 Other(String),
36}
37
38impl fmt::Display for WindowError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 WindowError::InvalidSelectionFormat => {
42 write!(f, "Invalid selection format. Use 'all', '1,2,3', or '1-3'")
43 }
44 WindowError::InvalidPositionSortFormat => {
45 write!(
46 f,
47 "Invalid position sort format. Use 'x1', 'y-1', or 'x1|y1'"
48 )
49 }
50 WindowError::InvalidRange => write!(f, "Invalid range format"),
51 WindowError::InvalidIndex => write!(f, "Invalid index"),
52 WindowError::InvalidSortOrder => {
53 write!(f, "Sort order must be 1 (ascending) or -1 (descending)")
54 }
55 WindowError::WindowsApiError(code) => write!(f, "Windows API error: 0x{:08x}", code),
56 WindowError::Other(msg) => write!(f, "{}", msg),
57 }
58 }
59}
60
61impl std::error::Error for WindowError {}
62
63#[cfg(feature = "windows")]
65impl From<windows::core::Error> for WindowError {
66 fn from(error: windows::core::Error) -> Self {
67 WindowError::WindowsApiError(error.code().0 as u32) }
69}
70
71pub type Result<T> = std::result::Result<T, WindowError>;