xee_xslt_ast/
error.rs

1use crate::{ast_core::Span, name::XmlName, value_template};
2
3#[derive(Debug, PartialEq)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize))]
5pub enum AttributeError {
6    // Expected attribute of name, not found (element span)
7    NotFound { name: XmlName, span: Span },
8    // Did not expect attribute of name (attribute span)
9    Unexpected { name: XmlName, span: Span },
10    // The value of an attribute was invalid
11    Invalid { value: String, span: Span },
12    // An eqname was invalid
13    InvalidEqName { value: String, span: Span },
14    // XPath parser error
15    XPathParser(xee_xpath_ast::ParserError),
16    // A value template could not be parsed
17    ValueTemplate(value_template::Error),
18    // Internal error; should not happen
19    Internal,
20}
21
22impl From<xee_xpath_ast::ParserError> for AttributeError {
23    fn from(e: xee_xpath_ast::ParserError) -> Self {
24        AttributeError::XPathParser(e)
25    }
26}
27
28impl From<value_template::Error> for AttributeError {
29    fn from(e: value_template::Error) -> Self {
30        AttributeError::ValueTemplate(e)
31    }
32}
33
34#[derive(Debug, PartialEq)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize))]
36pub enum ElementError {
37    // Did not expect this node
38    Unexpected { span: Span },
39    // Did not expect end TODO: how to get span info?
40    UnexpectedEnd,
41    // An attribute of the element was invalid
42    Attribute(AttributeError),
43    ValueTemplate(value_template::Error),
44    // XPath runtime error
45    XPathRunTime(xee_xpath_compiler::error::SpannedError),
46    // internal error, should not happen
47    Internal,
48    // Not yet supported
49    Unsupported,
50}
51
52impl From<AttributeError> for ElementError {
53    fn from(error: AttributeError) -> Self {
54        Self::Attribute(error)
55    }
56}
57
58impl From<xee_xpath_compiler::error::SpannedError> for ElementError {
59    fn from(e: xee_xpath_compiler::error::SpannedError) -> Self {
60        ElementError::XPathRunTime(e)
61    }
62}
63
64impl From<value_template::Error> for ElementError {
65    fn from(e: value_template::Error) -> Self {
66        ElementError::ValueTemplate(e)
67    }
68}
69
70impl From<xot::Error> for ElementError {
71    fn from(_e: xot::Error) -> Self {
72        ElementError::Internal
73    }
74}