diff options
author | 2025-04-12 11:56:21 +0100 | |
---|---|---|
committer | 2025-04-12 11:56:21 +0100 | |
commit | c658ab440f8e69ac406b18732dbf276c084926b6 (patch) | |
tree | f033b38c6a16c6a900eb37f56ad9ae6f362cb435 /src | |
parent | 3d575ec2a4440e7e4597761eab907d63ef91175e (diff) | |
download | peanuts-c658ab440f8e69ac406b18732dbf276c084926b6.tar.gz peanuts-c658ab440f8e69ac406b18732dbf276c084926b6.tar.bz2 peanuts-c658ab440f8e69ac406b18732dbf276c084926b6.zip |
feat: include input in parse error
Diffstat (limited to '')
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/reader.rs | 48 | ||||
-rw-r--r-- | src/xml/parsers_complete.rs | 7 |
3 files changed, 43 insertions, 14 deletions
diff --git a/src/error.rs b/src/error.rs index ae4aa26..717dfdd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -51,7 +51,7 @@ pub enum Error { #[error("utf8 conversion: {0}")] Utf8Error(#[from] Utf8Error), #[error("nom parsing: {0}")] - ParseError(String), + ParseError(String, String), #[error("unknown xml entity reference `&{0};`")] EntityProcessError(String), #[error("invalid character reference: {0}")] diff --git a/src/reader.rs b/src/reader.rs index 93b28af..c4d85f7 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -107,8 +107,12 @@ where self.read_buf().await?; } // TODO: better error - Err::Error(e) => return Err(Error::ParseError(e.to_string())), - Err::Failure(e) => return Err(Error::ParseError(e.to_string())), + Err::Error(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } + Err::Failure(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } }, } } @@ -150,8 +154,12 @@ where self.read_buf().await?; } // TODO: better error - Err::Error(e) => return Err(Error::ParseError(e.to_string())), - Err::Failure(e) => return Err(Error::ParseError(e.to_string())), + Err::Error(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } + Err::Failure(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } }, } } @@ -184,8 +192,12 @@ where self.read_buf().await?; } // TODO: better error - Err::Error(e) => return Err(Error::ParseError(e.to_string())), - Err::Failure(e) => return Err(Error::ParseError(e.to_string())), + Err::Error(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } + Err::Failure(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } }, } } @@ -215,8 +227,12 @@ where self.read_buf().await?; } // TODO: better error - Err::Error(e) => return Err(Error::ParseError(e.to_string())), - Err::Failure(e) => return Err(Error::ParseError(e.to_string())), + Err::Error(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } + Err::Failure(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } }, } } @@ -300,8 +316,12 @@ where self.read_buf().await?; } // TODO: better error - Err::Error(e) => return Err(Error::ParseError(e.to_string())), - Err::Failure(e) => return Err(Error::ParseError(e.to_string())), + Err::Error(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } + Err::Failure(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } }, }, }, @@ -361,8 +381,12 @@ where self.read_buf().await?; } // TODO: better error - Err::Error(e) => return Err(Error::ParseError(e.to_string())), - Err::Failure(e) => return Err(Error::ParseError(e.to_string())), + Err::Error(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } + Err::Failure(e) => { + return Err(Error::ParseError(input.to_string(), e.to_string())) + } }, } } diff --git a/src/xml/parsers_complete.rs b/src/xml/parsers_complete.rs index f18d0ff..1e2ac31 100644 --- a/src/xml/parsers_complete.rs +++ b/src/xml/parsers_complete.rs @@ -40,7 +40,12 @@ pub trait Parser<'s> { return Err(crate::error::Error::ExtraData(rest.to_string())); } } - Result::Err(e) => return Err(crate::error::Error::ParseError(e.to_string())), + Result::Err(e) => { + return Err(crate::error::Error::ParseError( + input.to_string(), + e.to_string(), + )) + } } } } |