Skip to main content

hyperstack_idl/
error.rs

1//! Error types for IDL search and lookup operations
2
3use crate::search::Suggestion;
4
5/// Structured error type for IDL lookup operations.
6///
7/// Named `IdlSearchError` to avoid conflict with `types::IdlError`
8/// which represents error definitions within an IDL spec.
9#[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 {}