2024-11-28 18:00:30 +00:00
|
|
|
use std::{
|
|
|
|
collections::{HashMap, VecDeque},
|
|
|
|
num::ParseIntError,
|
2025-02-25 18:08:20 +00:00
|
|
|
str::Utf8Error,
|
2024-11-28 18:00:30 +00:00
|
|
|
};
|
2024-11-10 14:31:43 +00:00
|
|
|
|
2025-02-25 18:08:20 +00:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
use crate::element::{Content, Name, NamespaceDeclaration};
|
2024-06-27 20:22:16 +01:00
|
|
|
|
2025-02-25 18:08:20 +00:00
|
|
|
#[derive(Error, Debug)]
|
2024-11-28 18:00:30 +00:00
|
|
|
pub enum DeserializeError {
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("could not parse string {0:?} to requested value")]
|
2024-11-28 18:00:30 +00:00
|
|
|
FromStr(String),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("unexpected attributes {0:?}")]
|
2024-11-28 18:00:30 +00:00
|
|
|
UnexpectedAttributes(HashMap<Name, String>),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("unexpected element content: {0:?}")]
|
2024-11-28 18:00:30 +00:00
|
|
|
UnexpectedContent(VecDeque<Content>),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("attribute `{0:?}` missing")]
|
2024-11-28 18:00:30 +00:00
|
|
|
MissingAttribute(Name),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("incorrect localname: expected `{expected:?}`, found `{found:?}`")]
|
|
|
|
IncorrectName { expected: String, found: String },
|
|
|
|
#[error("incorrect namespace: expected `{expected:?}`, found `{found:?}`")]
|
|
|
|
IncorrectNamespace { expected: String, found: String },
|
|
|
|
#[error("unqualified namespace: expected `{expected:?}`")]
|
|
|
|
Unqualified { expected: String },
|
|
|
|
#[error("element missing expected child")]
|
2024-11-28 18:00:30 +00:00
|
|
|
MissingChild,
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("element missing expected text value")]
|
2024-11-28 18:00:30 +00:00
|
|
|
MissingValue,
|
|
|
|
}
|
|
|
|
|
2025-02-25 18:08:20 +00:00
|
|
|
#[derive(Error, Debug)]
|
2024-06-27 20:22:16 +01:00
|
|
|
pub enum Error {
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
ReadError(#[from] std::io::Error),
|
|
|
|
#[error(transparent)]
|
|
|
|
Utf8Error(#[from] Utf8Error),
|
|
|
|
#[error("nom parse error: {0}")]
|
2024-06-27 20:22:16 +01:00
|
|
|
ParseError(String),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("unknown xml entity reference `&{0};`")]
|
2024-11-10 14:31:43 +00:00
|
|
|
EntityProcessError(String),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
InvalidCharRef(CharRefError),
|
|
|
|
#[error("duplicate namespace declaration: {0:?}")]
|
2024-11-19 14:52:14 +00:00
|
|
|
DuplicateNameSpaceDeclaration(NamespaceDeclaration),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("duplicate attribute: {0}")]
|
2024-11-10 14:31:43 +00:00
|
|
|
DuplicateAttribute(String),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("mismatched end tag: expected `{0:?}`, found `{1:?}`")]
|
2024-11-19 16:26:59 +00:00
|
|
|
MismatchedEndTag(Name, Name),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("not currently in any element")]
|
2024-11-10 22:28:55 +00:00
|
|
|
NotInElement(String),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("extra unexpected data included in complete parse: `{0}`")]
|
2024-11-19 14:52:14 +00:00
|
|
|
ExtraData(String),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("namespace `{0}` has not previously been declared")]
|
2024-11-20 15:10:36 +00:00
|
|
|
UndeclaredNamespace(String),
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error(transparent)]
|
|
|
|
Deserialize(#[from] DeserializeError),
|
2025-01-12 16:46:14 +00:00
|
|
|
/// root element end tag already processed
|
2025-02-25 18:08:20 +00:00
|
|
|
#[error("root element has already been fully processed")]
|
2025-01-12 16:46:14 +00:00
|
|
|
RootElementEnded,
|
2024-11-28 18:00:30 +00:00
|
|
|
}
|
|
|
|
|
2025-02-25 18:08:20 +00:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum CharRefError {
|
|
|
|
#[error(transparent)]
|
|
|
|
ParseInt(#[from] ParseIntError),
|
|
|
|
#[error("u32 `{0}` does not represent a valid char")]
|
|
|
|
IntegerNotAChar(u32),
|
|
|
|
#[error("`{0}` is not a valid xml char")]
|
|
|
|
InvalidXMLChar(char),
|
2024-11-10 14:31:43 +00:00
|
|
|
}
|