use std::{ collections::{HashMap, VecDeque}, num::ParseIntError, str::Utf8Error, }; use thiserror::Error; use crate::element::{Content, Name, NamespaceDeclaration}; #[derive(Error, Debug)] pub enum DeserializeError { #[error("could not parse string {0:?} to requested value")] FromStr(String), #[error("unexpected attributes {0:?}")] UnexpectedAttributes(HashMap), #[error("unexpected element content: {0:?}")] UnexpectedContent(VecDeque), #[error("attribute `{0:?}` missing")] MissingAttribute(Name), #[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")] MissingChild, #[error("element missing expected text value")] MissingValue, } #[derive(Error, Debug)] pub enum Error { #[error(transparent)] ReadError(#[from] std::io::Error), #[error(transparent)] Utf8Error(#[from] Utf8Error), #[error("nom parse error: {0}")] ParseError(String), #[error("unknown xml entity reference `&{0};`")] EntityProcessError(String), #[error(transparent)] InvalidCharRef(CharRefError), #[error("duplicate namespace declaration: {0:?}")] DuplicateNameSpaceDeclaration(NamespaceDeclaration), #[error("duplicate attribute: {0}")] DuplicateAttribute(String), #[error("mismatched end tag: expected `{0:?}`, found `{1:?}`")] MismatchedEndTag(Name, Name), #[error("not currently in any element")] NotInElement(String), #[error("extra unexpected data included in complete parse: `{0}`")] ExtraData(String), #[error("namespace `{0}` has not previously been declared")] UndeclaredNamespace(String), #[error(transparent)] Deserialize(#[from] DeserializeError), /// root element end tag already processed #[error("root element has already been fully processed")] RootElementEnded, } #[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), }