Skip to main content

webui_parser/
error.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3
4//! Error handling for the WebUI parser.
5
6use std::fmt;
7
8/// Result type for WebUI parser operations.
9pub type Result<T> = std::result::Result<T, ParserError>;
10
11/// Error type for WebUI parser.
12#[derive(Debug)]
13pub enum ParserError {
14    /// Generic error.
15    Generic(String),
16
17    /// I/O error.
18    IO(String),
19
20    /// Parse error.
21    Parse(String),
22
23    /// Component error.
24    Component(String),
25
26    /// CSS error.
27    Css(String),
28
29    /// HTML error.
30    Html(String),
31
32    /// Directive error.
33    Directive(String),
34
35    /// Entity not found error.
36    NotFound(String),
37
38    /// TypeScript parse error.
39    TsParseError(String),
40}
41
42impl fmt::Display for ParserError {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            Self::Generic(msg) => write!(f, "Generic error: {}", msg),
46            Self::IO(msg) => write!(f, "I/O error: {}", msg),
47            Self::Parse(msg) => write!(f, "Parse error: {}", msg),
48            Self::Component(msg) => write!(f, "Component error: {}", msg),
49            Self::Css(msg) => write!(f, "CSS error: {}", msg),
50            Self::Html(msg) => write!(f, "HTML error: {}", msg),
51            Self::Directive(msg) => write!(f, "Directive error: {}", msg),
52            Self::NotFound(msg) => write!(f, "Not found: {}", msg),
53            Self::TsParseError(msg) => write!(f, "TypeScript parse error: {}", msg),
54        }
55    }
56}
57
58impl std::error::Error for ParserError {}