implement Clone and other improvements for Error

This commit is contained in:
cel 🌸 2025-02-25 20:39:06 +00:00
parent c4e204db64
commit 2b399fb59d
1 changed files with 25 additions and 12 deletions

View File

@ -2,13 +2,17 @@ use std::{
collections::{HashMap, VecDeque},
num::ParseIntError,
str::Utf8Error,
sync::Arc,
};
use thiserror::Error;
use crate::element::{Content, Name, NamespaceDeclaration};
use crate::{
element::{Content, Name, NamespaceDeclaration},
Element,
};
#[derive(Error, Debug)]
#[derive(Error, Debug, Clone)]
pub enum DeserializeError {
#[error("could not parse string {0:?} to requested value")]
FromStr(String),
@ -28,19 +32,23 @@ pub enum DeserializeError {
MissingChild,
#[error("element missing expected text value")]
MissingValue,
// not used by crate (yet), but may be used by consumers implementing FromElement
#[error("unexpected element: {0:?}")]
UnexpectedElement(Element),
}
#[derive(Error, Debug)]
#[derive(Error, Debug, Clone)]
pub enum Error {
#[error(transparent)]
ReadError(#[from] std::io::Error),
#[error(transparent)]
#[error("io: {0}")]
// TODO: is this okay?
ReadError(Arc<std::io::Error>),
#[error("utf8 conversion: {0}")]
Utf8Error(#[from] Utf8Error),
#[error("nom parse error: {0}")]
#[error("nom parsing: {0}")]
ParseError(String),
#[error("unknown xml entity reference `&{0};`")]
EntityProcessError(String),
#[error(transparent)]
#[error("invalid character reference: {0}")]
InvalidCharRef(CharRefError),
#[error("duplicate namespace declaration: {0:?}")]
DuplicateNameSpaceDeclaration(NamespaceDeclaration),
@ -54,16 +62,21 @@ pub enum Error {
ExtraData(String),
#[error("namespace `{0}` has not previously been declared")]
UndeclaredNamespace(String),
#[error(transparent)]
#[error("deserialization error: {0}")]
Deserialize(#[from] DeserializeError),
/// root element end tag already processed
#[error("root element has already been fully processed")]
RootElementEnded,
}
#[derive(Error, Debug)]
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::ReadError(Arc::new(e))
}
}
#[derive(Error, Debug, Clone)]
pub enum CharRefError {
#[error(transparent)]
#[error("int parsing: {0}")]
ParseInt(#[from] ParseIntError),
#[error("u32 `{0}` does not represent a valid char")]
IntegerNotAChar(u32),