aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml/mod.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-02-25 18:08:20 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-02-25 18:08:20 +0000
commitfe389c38ca2ff23e3f2bd2305b455e4d551a9ccc (patch)
tree11fe43131016adc290a4bc381dd5ede34679dc5b /src/xml/mod.rs
parentbbb1452905a3f59e178031bb3eeca4d963e50394 (diff)
downloadpeanuts-fe389c38ca2ff23e3f2bd2305b455e4d551a9ccc.tar.gz
peanuts-fe389c38ca2ff23e3f2bd2305b455e4d551a9ccc.tar.bz2
peanuts-fe389c38ca2ff23e3f2bd2305b455e4d551a9ccc.zip
implement proper errors with thiserror
Diffstat (limited to '')
-rw-r--r--src/xml/mod.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index 43f3027..3982070 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -2,7 +2,7 @@ use std::{char, convert::Infallible, ops::Deref, str::FromStr};
use parsers_complete::Parser;
-use crate::error::Error;
+use crate::error::{CharRefError, Error};
pub mod composers;
pub mod parsers;
@@ -736,23 +736,23 @@ impl<'s> CharRef<'s> {
let int: u32;
match self {
CharRef::Decimal(dec) => {
- int = dec.parse()?;
+ int = dec
+ .parse()
+ .map_err(|e| Error::InvalidCharRef(CharRefError::ParseInt(e)))?;
}
CharRef::Hexadecimal(hex) => {
- int = <u32>::from_str_radix(hex, 16)?;
+ int = <u32>::from_str_radix(hex, 16)
+ .map_err(|e| Error::InvalidCharRef(CharRefError::ParseInt(e)))?;
}
}
let c = std::char::from_u32(int);
- let c = c.ok_or_else(|| Error::InvalidCharRef(int.to_string()))?;
+ let c = c.ok_or_else(|| Error::InvalidCharRef(CharRefError::IntegerNotAChar(int)))?;
if matches!(c, '\u{9}' | '\u{A}' | '\u{D}' | '\u{20}'..='\u{D7FF}' | '\u{E000}'..='\u{FFFD}' | '\u{10000}'..='\u{10FFFF}')
{
return Ok(c);
} else {
- return Err(Error::InvalidCharRef(format!(
- "{} is not a valid xml char",
- c
- )));
+ return Err(Error::InvalidCharRef(CharRefError::InvalidXMLChar(c)));
};
}
}