Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework errors #675

Merged
merged 24 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e0adb66
Normalize failed text of all checks for expected errors
Mingun Oct 20, 2023
da2823d
cargo fmt
Mingun Oct 21, 2023
d9520c4
Remove `DeError::UnexpectedEnd`, because this error could be returned…
Mingun Oct 7, 2023
77e5a2c
Remove `DeError::ExpectedStart`, call `Visitor::visit_borrowed_str` o…
Mingun Oct 7, 2023
a5490f2
Do not return `DeError::Unsupported` in `SimpleTypeDeserializer`, cal…
Mingun Oct 20, 2023
f845369
Do not return `DeError::Unsupported` in attempt to deserialize byte data
Mingun Oct 20, 2023
77a2fad
Do not return `DeError::Unsupported` in attempt to deserialize newtyp…
Mingun Oct 20, 2023
29ca886
Replace `Error::UnexpectedEof` and `Error::UnexpectedBang` by `Error:…
Mingun Sep 28, 2023
0e5188d
Replace `Error::UnexpectedEof` by `Error::IllFormed(MissedEnd)` in re…
Mingun Sep 27, 2023
f7ee91f
Do not convert `DeError::InvalidXml(Error::IllFormed(MissedEnd))` to …
Mingun Oct 7, 2023
a91843e
Replace `DeError::UnexpectedEof` by `Error::IllFormed(MissedEnd)` whe…
Mingun Oct 28, 2023
7d20324
Replace `DeError::UnexpectedEof` by `Error::IllFormed(MissedEnd)` in …
Mingun Oct 21, 2023
4972d4f
Replace `DeError::UnexpectedEof` by `Error::IllFormed(MissedEnd)` and…
Mingun Oct 21, 2023
cee2725
`DeEvent::Eof` is impossible in `MapValueDeserializer::variant_seed`,…
Mingun Oct 21, 2023
d5489df
Remove unnecessary allocation
Mingun Oct 8, 2023
00de446
Report trimmed found name in EndEventMismatch error when end tag has …
Mingun Sep 28, 2023
ff28390
Report EndEventMismatch error at start of the end tag at `<` character
Mingun Sep 28, 2023
73fcf23
Inline mismatch_err closure because in the next commit it will genera…
Mingun Sep 28, 2023
6670800
Replace `Error::EndEventMismatch` by `Error::IllFormed(UnmatchedEnd)`…
Mingun Sep 28, 2023
4d887a2
Replace `Error::EndEventMismatch` by `Error::IllFormed(MismatchedEnd)`
Mingun Sep 28, 2023
a4febad
`IllFormed(UnmatchedEnd)` should be reported always because lone clos…
Mingun Sep 29, 2023
596edd6
Replace `Error::UnexpectedToken` by `Error::IllFormed(DoubleHyphenInC…
Mingun Oct 28, 2023
53c6b4e
Remove not used `Error::TextNotFound`
Mingun Oct 28, 2023
a049cd2
Better document `Error::XmlDeclWithoutVersion` and `Error::EmptyDocType`
Mingun Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,7 @@ macro_rules! deserialize_primitives {
}

/// Character represented as [strings](#method.deserialize_str).
#[inline]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you actually found this to make a difference?

The primary purpose of #[inline] is to allow inlining across compilation units. Within a compilation unit, the compiler is just going to decide on its own and mostly ignore this attribute unless you say #[inline(always)].

If these functions are not going to be called from any external library, I doubt it would make a difference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, added just for consistence. Actually I want to run some profiler one day, just need time to learn how to do that and find a which one that could be run on Windows. Most tools supports only Linux. cargo flamegraph looks promising.

fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
Expand All @@ -1886,22 +1887,25 @@ macro_rules! deserialize_primitives {
}

/// Representation of owned strings the same as [non-owned](#method.deserialize_str).
#[inline]
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_str(visitor)
}

/// Returns [`DeError::Unsupported`]
fn deserialize_bytes<V>(self, _visitor: V) -> Result<V::Value, DeError>
/// Forwards deserialization to the [`deserialize_any`](#method.deserialize_any).
#[inline]
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
Err(DeError::Unsupported("binary data content is not supported by XML format".into()))
self.deserialize_any(visitor)
}

/// Forwards deserialization to the [`deserialize_bytes`](#method.deserialize_bytes).
#[inline]
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
Expand All @@ -1910,6 +1914,7 @@ macro_rules! deserialize_primitives {
}

/// Representation of the named units the same as [unnamed units](#method.deserialize_unit).
#[inline]
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
Expand All @@ -1922,6 +1927,7 @@ macro_rules! deserialize_primitives {
}

/// Representation of tuples the same as [sequences](#method.deserialize_seq).
#[inline]
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
Expand All @@ -1930,6 +1936,7 @@ macro_rules! deserialize_primitives {
}

/// Representation of named tuples the same as [unnamed tuples](#method.deserialize_tuple).
#[inline]
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
Expand All @@ -1953,6 +1960,7 @@ macro_rules! deserialize_primitives {
}

/// Identifiers represented as [strings](#method.deserialize_str).
#[inline]
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
Expand Down
14 changes: 4 additions & 10 deletions tests/serde-de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@ mod trivial {
#[test]
fn byte_buf() {
match from_str::<ByteBuf>($value) {
Err(DeError::Unsupported(msg)) => {
assert_eq!(msg, "binary data content is not supported by XML format")
}
Err(DeError::UnexpectedEof) => {}
x => panic!(
r#"Expected `Err(Unsupported("binary data content is not supported by XML format"))`, but got `{:?}`"#,
r#"Expected `Err(UnexpectedEof)`, but got `{:?}`"#,
x
),
}
Expand All @@ -144,11 +142,9 @@ mod trivial {
#[test]
fn bytes() {
match from_str::<Bytes>($value) {
Err(DeError::Unsupported(msg)) => {
assert_eq!(msg, "binary data content is not supported by XML format")
}
Err(DeError::UnexpectedEof) => {}
x => panic!(
r#"Expected `Err(Unsupported("binary data content is not supported by XML format"))`, but got `{:?}`"#,
r#"Expected `Err(UnexpectedEof)`, but got `{:?}`"#,
x
),
}
Expand All @@ -170,15 +166,13 @@ mod trivial {
/// Empty document should considered invalid no matter what type we try to deserialize
mod empty_doc {
use super::*;
use pretty_assertions::assert_eq;

eof!("");
}

/// Document that contains only comment should be handled as if it is empty
mod only_comment {
use super::*;
use pretty_assertions::assert_eq;

eof!("<!--comment-->");
}
Expand Down