1use crate::search::Suggestion;
4
5#[derive(Debug, Clone)]
10pub enum IdlSearchError {
11 NotFound {
12 input: String,
13 section: String,
14 suggestions: Vec<Suggestion>,
15 available: Vec<String>,
16 },
17 ParseError {
18 path: String,
19 source: String,
20 },
21 InvalidPath {
22 path: String,
23 },
24}
25
26impl std::fmt::Display for IdlSearchError {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 match self {
29 IdlSearchError::NotFound {
30 input,
31 section,
32 suggestions,
33 ..
34 } => {
35 write!(f, "Not found: '{}' in {}", input, section)?;
36 if !suggestions.is_empty() {
37 write!(f, ". Did you mean: {}?", suggestions[0].candidate)?;
38 }
39 Ok(())
40 }
41 IdlSearchError::ParseError { path, source } => {
42 write!(f, "Parse error in {}: {}", path, source)
43 }
44 IdlSearchError::InvalidPath { path } => write!(f, "Invalid path: {}", path),
45 }
46 }
47}
48
49impl std::error::Error for IdlSearchError {}