xml: Move Error to own module

This commit is contained in:
Lennart
2024-12-25 17:50:26 +01:00
parent b9edc295a8
commit 5ffc5037db
3 changed files with 28 additions and 27 deletions

View File

@@ -6,33 +6,8 @@ pub use xml_derive::XmlDocument;
pub use xml_derive::XmlRootTag; pub use xml_derive::XmlRootTag;
use quick_xml::events::{BytesStart, Event}; use quick_xml::events::{BytesStart, Event};
use thiserror::Error;
#[derive(Debug, Error)] use crate::XmlDeError;
pub enum XmlDeError {
#[error(transparent)]
QuickXmlError(#[from] quick_xml::Error),
#[error(transparent)]
QuickXmlAttrError(#[from] quick_xml::events::attributes::AttrError),
#[error("Unknown error")]
UnknownError,
#[error("Invalid tag [{0}]{1}. Expected [{2}]{3}")]
InvalidTag(String, String, String, String),
#[error("Missing field {0}")]
MissingField(&'static str),
#[error("End of file, expected closing tags")]
Eof,
#[error("Unsupported xml event: {0}")]
UnsupportedEvent(&'static str),
#[error("{0}")]
Other(String),
#[error("Invalid variant: {0}")]
InvalidVariant(String),
#[error("Invalid field name in {0}: {1}")]
InvalidFieldName(&'static str, String),
#[error(transparent)]
InvalidValue(#[from] crate::value::ParseValueError),
}
pub trait XmlDeserialize: Sized { pub trait XmlDeserialize: Sized {
fn deserialize<R: BufRead>( fn deserialize<R: BufRead>(

25
crates/xml/src/error.rs Normal file
View File

@@ -0,0 +1,25 @@
use thiserror::Error;
#[derive(Debug, Error)]
pub enum XmlDeError {
#[error(transparent)]
QuickXmlError(#[from] quick_xml::Error),
#[error(transparent)]
QuickXmlAttrError(#[from] quick_xml::events::attributes::AttrError),
#[error("Unknown error")]
UnknownError,
#[error("Invalid tag [{0}]{1}. Expected [{2}]{3}")]
InvalidTag(String, String, String, String),
#[error("Missing field {0}")]
MissingField(&'static str),
#[error("End of file, expected closing tags")]
Eof,
#[error("Unsupported xml event: {0}")]
UnsupportedEvent(&'static str),
#[error("Invalid variant: {0}")]
InvalidVariant(String),
#[error("Invalid field name in {0}: {1}")]
InvalidFieldName(&'static str, String),
#[error(transparent)]
InvalidValue(#[from] crate::value::ParseValueError),
}

View File

@@ -2,13 +2,14 @@ use quick_xml::events::{BytesStart, Event};
use std::io::BufRead; use std::io::BufRead;
pub mod de; pub mod de;
mod error;
pub mod se; pub mod se;
mod value; mod value;
pub use de::XmlDeError;
pub use de::XmlDeserialize; pub use de::XmlDeserialize;
pub use de::XmlDocument; pub use de::XmlDocument;
pub use de::XmlRootTag; pub use de::XmlRootTag;
pub use error::XmlDeError;
pub use se::XmlSerialize; pub use se::XmlSerialize;
pub use value::Value; pub use value::Value;