aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-02-25 20:39:06 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-02-25 20:47:55 +0000
commit2b399fb59d17bc127fbcd1533a3c079bc86770e1 (patch)
tree7fa421ad7b7db8534f71c942d7895a4ab265811e
parentc4e204db6451c857a2c6d70832b2619024fd3c44 (diff)
downloadpeanuts-2b399fb59d17bc127fbcd1533a3c079bc86770e1.tar.gz
peanuts-2b399fb59d17bc127fbcd1533a3c079bc86770e1.tar.bz2
peanuts-2b399fb59d17bc127fbcd1533a3c079bc86770e1.zip
implement Clone and other improvements for Error
-rw-r--r--src/error.rs37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/error.rs b/src/error.rs
index 65a1503..9337556 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -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),