1use std::fmt;
2
3#[derive(Debug)]
4pub enum SearchError {
5 InvalidPattern(String),
6 InvalidGlob(String),
7 InvalidType(String),
8 Walk(ignore::Error),
9 Io(std::io::Error),
10}
11
12impl fmt::Display for SearchError {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Self::InvalidPattern(message) => write!(f, "invalid pattern: {message}"),
16 Self::InvalidGlob(message) => write!(f, "invalid glob: {message}"),
17 Self::InvalidType(message) => write!(f, "invalid type: {message}"),
18 Self::Walk(err) => write!(f, "walk error: {err}"),
19 Self::Io(err) => write!(f, "io error: {err}"),
20 }
21 }
22}
23
24impl std::error::Error for SearchError {
25 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26 match self {
27 Self::InvalidPattern(_) | Self::InvalidGlob(_) | Self::InvalidType(_) => None,
28 Self::Walk(err) => Some(err),
29 Self::Io(err) => Some(err),
30 }
31 }
32}
33
34impl From<ignore::Error> for SearchError {
35 fn from(err: ignore::Error) -> Self {
36 Self::Walk(err)
37 }
38}
39
40impl From<std::io::Error> for SearchError {
41 fn from(err: std::io::Error) -> Self {
42 Self::Io(err)
43 }
44}