Skip to content

Commit 2c55638

Browse files
Mingundralley
andcommitted
Rename IllFormed errors based on feedback
Co-authored-by: Daniel Alley <[email protected]>
1 parent 55039e8 commit 2c55638

File tree

11 files changed

+68
-66
lines changed

11 files changed

+68
-66
lines changed

Changelog.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ configuration is serializable.
2727

2828
- [#622]: Fix wrong disregarding of not closed markup, such as lone `<`.
2929
- [#684]: Fix incorrect position reported for `Error::IllFormed(DoubleHyphenInComment)`.
30-
- [#684]: Fix incorrect position reported for `Error::IllFormed(MissedDoctypeName)`.
30+
- [#684]: Fix incorrect position reported for `Error::IllFormed(MissingDoctypeName)`.
3131

3232
### Misc Changes
3333

3434
- [#675]: Minimum supported version of serde raised to 1.0.139
3535
- [#675]: Rework the `quick_xml::Error` type to provide more accurate information:
36-
- `Error::EndEventMismatch` replaced by `IllFormedError::MismatchedEnd` in some cases
37-
- `Error::EndEventMismatch` replaced by `IllFormedError::UnmatchedEnd` in some cases
36+
- `Error::EndEventMismatch` replaced by `IllFormedError::MismatchedEndTag` in some cases
37+
- `Error::EndEventMismatch` replaced by `IllFormedError::UnmatchedEndTag` in some cases
3838
- `Error::TextNotFound` was removed because not used
3939
- `Error::UnexpectedBang` replaced by `SyntaxError`
4040
- `Error::UnexpectedEof` replaced by `SyntaxError` in some cases
4141
- `Error::UnexpectedEof` replaced by `IllFormedError` in some cases
4242
- `Error::UnexpectedToken` replaced by `IllFormedError::DoubleHyphenInComment`
43-
- `Error::XmlDeclWithoutVersion` replaced by `IllFormedError::MissedVersion` (in [#684])
44-
- `Error::EmptyDocType` replaced by `IllFormedError::MissedDoctypeName` (in [#684])
43+
- `Error::XmlDeclWithoutVersion` replaced by `IllFormedError::MissingDeclVersion` (in [#684])
44+
- `Error::EmptyDocType` replaced by `IllFormedError::MissingDoctypeName` (in [#684])
4545
- [#684]: Changed positions reported for `SyntaxError`s: now they are always points
4646
to the start of markup (i. e. to the `<` character) with error.
4747
- [#684]: Now `<??>` parsed as `Event::PI` with empty content instead of raising

src/de/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ where
26492649
/// |[`DeEvent::Start`]|`<any-tag>...</any-tag>` |Emits [`UnexpectedStart("any-tag")`](DeError::UnexpectedStart)
26502650
/// |[`DeEvent::End`] |`</tag>` |Returns an empty slice. The reader guarantee that tag will match the open one
26512651
/// |[`DeEvent::Text`] |`text content` or `<![CDATA[cdata content]]>` (probably mixed)|Returns event content unchanged, expects the `</tag>` after that
2652-
/// |[`DeEvent::Eof`] | |Emits [`InvalidXml(IllFormed(MissedEnd))`](DeError::InvalidXml)
2652+
/// |[`DeEvent::Eof`] | |Emits [`InvalidXml(IllFormed(MissingEndTag))`](DeError::InvalidXml)
26532653
///
26542654
/// [`Text`]: Event::Text
26552655
/// [`CData`]: Event::CData
@@ -3642,7 +3642,7 @@ mod tests {
36423642

36433643
match de.read_to_end(QName(b"tag")) {
36443644
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
3645-
assert_eq!(cause, IllFormedError::MissedEnd("tag".into()))
3645+
assert_eq!(cause, IllFormedError::MissingEndTag("tag".into()))
36463646
}
36473647
x => panic!(
36483648
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -3661,7 +3661,7 @@ mod tests {
36613661

36623662
match de.read_to_end(QName(b"tag")) {
36633663
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
3664-
assert_eq!(cause, IllFormedError::MissedEnd("tag".into()))
3664+
assert_eq!(cause, IllFormedError::MissingEndTag("tag".into()))
36653665
}
36663666
x => panic!(
36673667
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -3756,7 +3756,7 @@ mod tests {
37563756
fn read_string() {
37573757
match from_str::<String>(r#"</root>"#) {
37583758
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
3759-
assert_eq!(cause, IllFormedError::UnmatchedEnd("root".into()));
3759+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("root".into()));
37603760
}
37613761
x => panic!(
37623762
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -3770,7 +3770,7 @@ mod tests {
37703770
match from_str::<String>(r#"<root></other>"#) {
37713771
Err(DeError::InvalidXml(Error::IllFormed(cause))) => assert_eq!(
37723772
cause,
3773-
IllFormedError::MismatchedEnd {
3773+
IllFormedError::MismatchedEndTag {
37743774
expected: "root".into(),
37753775
found: "other".into(),
37763776
}
@@ -4098,7 +4098,7 @@ mod tests {
40984098
assert_eq!(de.next().unwrap(), DeEvent::End(BytesEnd::new("tag")));
40994099
match de.next() {
41004100
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
4101-
assert_eq!(cause, IllFormedError::UnmatchedEnd("tag2".into()));
4101+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("tag2".into()));
41024102
}
41034103
x => panic!(
41044104
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -4241,7 +4241,7 @@ mod tests {
42414241
let mut de = make_de("</tag>");
42424242
match de.next() {
42434243
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
4244-
assert_eq!(cause, IllFormedError::UnmatchedEnd("tag".into()));
4244+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("tag".into()));
42454245
}
42464246
x => panic!(
42474247
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -4320,7 +4320,7 @@ mod tests {
43204320
assert_eq!(de.next().unwrap(), DeEvent::Text("text".into()));
43214321
match de.next() {
43224322
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
4323-
assert_eq!(cause, IllFormedError::UnmatchedEnd("tag".into()));
4323+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("tag".into()));
43244324
}
43254325
x => panic!(
43264326
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -4352,7 +4352,7 @@ mod tests {
43524352
assert_eq!(de.next().unwrap(), DeEvent::Text("text cdata ".into()));
43534353
match de.next() {
43544354
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
4355-
assert_eq!(cause, IllFormedError::UnmatchedEnd("tag".into()));
4355+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("tag".into()));
43564356
}
43574357
x => panic!(
43584358
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -4458,7 +4458,7 @@ mod tests {
44584458
assert_eq!(de.next().unwrap(), DeEvent::Text(" cdata ".into()));
44594459
match de.next() {
44604460
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
4461-
assert_eq!(cause, IllFormedError::UnmatchedEnd("tag".into()));
4461+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("tag".into()));
44624462
}
44634463
x => panic!(
44644464
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -4488,7 +4488,7 @@ mod tests {
44884488
assert_eq!(de.next().unwrap(), DeEvent::Text(" cdata text".into()));
44894489
match de.next() {
44904490
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
4491-
assert_eq!(cause, IllFormedError::UnmatchedEnd("tag".into()));
4491+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("tag".into()));
44924492
}
44934493
x => panic!(
44944494
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",
@@ -4538,7 +4538,7 @@ mod tests {
45384538
assert_eq!(de.next().unwrap(), DeEvent::Text(" cdata cdata2 ".into()));
45394539
match de.next() {
45404540
Err(DeError::InvalidXml(Error::IllFormed(cause))) => {
4541-
assert_eq!(cause, IllFormedError::UnmatchedEnd("tag".into()));
4541+
assert_eq!(cause, IllFormedError::UnmatchedEndTag("tag".into()));
45424542
}
45434543
x => panic!(
45444544
"Expected `Err(InvalidXml(IllFormed(_)))`, but got `{:?}`",

src/errors.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,26 @@ pub enum IllFormedError {
8181
/// the declaration. In the last case it contains the name of the found attribute.
8282
///
8383
/// [specification]: https://www.w3.org/TR/xml11/#sec-prolog-dtd
84-
MissedVersion(Option<String>),
84+
MissingDeclVersion(Option<String>),
8585
/// A document type definition (DTD) does not contain a name of a root element.
8686
///
8787
/// According to the [specification], document type definition (`<!DOCTYPE foo>`)
8888
/// MUST contain a name which defines a document type (`foo`). If that name
8989
/// is missed, this error is returned.
9090
///
9191
/// [specification]: https://www.w3.org/TR/xml11/#NT-doctypedecl
92-
MissedDoctypeName,
92+
MissingDoctypeName,
9393
/// The end tag was not found during reading of a sub-tree of elements due to
9494
/// encountering an EOF from the underlying reader. This error is returned from
9595
/// [`Reader::read_to_end`].
9696
///
9797
/// [`Reader::read_to_end`]: crate::reader::Reader::read_to_end
98-
MissedEnd(String),
98+
MissingEndTag(String),
9999
/// The specified end tag was encountered without corresponding open tag at the
100100
/// same level of hierarchy
101-
UnmatchedEnd(String),
101+
UnmatchedEndTag(String),
102102
/// The specified end tag does not match the start tag at that nesting level.
103-
MismatchedEnd {
103+
MismatchedEndTag {
104104
/// Name of open tag, that is expected to be closed
105105
expected: String,
106106
/// Name of actually closed tag
@@ -122,25 +122,25 @@ pub enum IllFormedError {
122122
impl fmt::Display for IllFormedError {
123123
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
124124
match self {
125-
Self::MissedVersion(None) => {
125+
Self::MissingDeclVersion(None) => {
126126
write!(f, "an XML declaration does not contain `version` attribute")
127127
}
128-
Self::MissedVersion(Some(attr)) => {
128+
Self::MissingDeclVersion(Some(attr)) => {
129129
write!(f, "an XML declaration must start with `version` attribute, but in starts with `{}`", attr)
130130
}
131-
Self::MissedDoctypeName => write!(
131+
Self::MissingDoctypeName => write!(
132132
f,
133133
"`<!DOCTYPE>` declaration does not contain a name of a document type"
134134
),
135-
Self::MissedEnd(tag) => write!(
135+
Self::MissingEndTag(tag) => write!(
136136
f,
137137
"start tag not closed: `</{}>` not found before end of input",
138138
tag,
139139
),
140-
Self::UnmatchedEnd(tag) => {
140+
Self::UnmatchedEndTag(tag) => {
141141
write!(f, "close tag `</{}>` does not match any open tag", tag)
142142
}
143-
Self::MismatchedEnd { expected, found } => write!(
143+
Self::MismatchedEndTag { expected, found } => write!(
144144
f,
145145
"expected `</{}>`, but `</{}>` was found",
146146
expected, found,
@@ -199,7 +199,7 @@ pub enum Error {
199199
impl Error {
200200
pub(crate) fn missed_end(name: QName, decoder: Decoder) -> Self {
201201
match decoder.decode(name.as_ref()) {
202-
Ok(name) => IllFormedError::MissedEnd(name.into()).into(),
202+
Ok(name) => IllFormedError::MissingEndTag(name.into()).into(),
203203
Err(err) => err.into(),
204204
}
205205
}

src/events/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'a> BytesDecl<'a> {
391391
/// In case of multiple attributes value of the first one is returned.
392392
///
393393
/// If version is missed in the declaration, or the first thing is not a version,
394-
/// [`IllFormedError::MissedVersion`] will be returned.
394+
/// [`IllFormedError::MissingDeclVersion`] will be returned.
395395
///
396396
/// # Examples
397397
///
@@ -410,21 +410,21 @@ impl<'a> BytesDecl<'a> {
410410
/// // <?xml encoding='utf-8'?>
411411
/// let decl = BytesDecl::from_start(BytesStart::from_content(" encoding='utf-8'", 0));
412412
/// match decl.version() {
413-
/// Err(Error::IllFormed(IllFormedError::MissedVersion(Some(key)))) => assert_eq!(key, "encoding"),
413+
/// Err(Error::IllFormed(IllFormedError::MissingDeclVersion(Some(key)))) => assert_eq!(key, "encoding"),
414414
/// _ => assert!(false),
415415
/// }
416416
///
417417
/// // <?xml encoding='utf-8' version='1.1'?>
418418
/// let decl = BytesDecl::from_start(BytesStart::from_content(" encoding='utf-8' version='1.1'", 0));
419419
/// match decl.version() {
420-
/// Err(Error::IllFormed(IllFormedError::MissedVersion(Some(key)))) => assert_eq!(key, "encoding"),
420+
/// Err(Error::IllFormed(IllFormedError::MissingDeclVersion(Some(key)))) => assert_eq!(key, "encoding"),
421421
/// _ => assert!(false),
422422
/// }
423423
///
424424
/// // <?xml?>
425425
/// let decl = BytesDecl::from_start(BytesStart::from_content("", 0));
426426
/// match decl.version() {
427-
/// Err(Error::IllFormed(IllFormedError::MissedVersion(None))) => {},
427+
/// Err(Error::IllFormed(IllFormedError::MissingDeclVersion(None))) => {},
428428
/// _ => assert!(false),
429429
/// }
430430
/// ```
@@ -437,12 +437,14 @@ impl<'a> BytesDecl<'a> {
437437
// first attribute was not "version"
438438
Some(Ok(a)) => {
439439
let found = from_utf8(a.key.as_ref())?.to_string();
440-
Err(Error::IllFormed(IllFormedError::MissedVersion(Some(found))))
440+
Err(Error::IllFormed(IllFormedError::MissingDeclVersion(Some(
441+
found,
442+
))))
441443
}
442444
// error parsing attributes
443445
Some(Err(e)) => Err(e.into()),
444446
// no attributes
445-
None => Err(Error::IllFormed(IllFormedError::MissedVersion(None))),
447+
None => Err(Error::IllFormed(IllFormedError::MissingDeclVersion(None))),
446448
}
447449
}
448450

src/reader/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct Config {
4040
pub check_comments: bool,
4141

4242
/// Whether mismatched closing tag names should be detected. If enabled, in
43-
/// case of mismatch the [`Error::IllFormed(MismatchedEnd)`] is returned from
43+
/// case of mismatch the [`Error::IllFormed(MismatchedEndTag)`] is returned from
4444
/// read methods.
4545
///
4646
/// Note, that start and end tags [should match literally][spec], they cannot
@@ -71,7 +71,7 @@ pub struct Config {
7171
///
7272
/// Default: `true`
7373
///
74-
/// [`Error::IllFormed(MismatchedEnd)`]: crate::errors::IllFormedError::MismatchedEnd
74+
/// [`Error::IllFormed(MismatchedEndTag)`]: crate::errors::IllFormedError::MismatchedEndTag
7575
/// [spec]: https://www.w3.org/TR/xml11/#dt-etag
7676
/// [`End`]: crate::events::Event::End
7777
/// [`expand_empty_elements`]: Self::expand_empty_elements

src/reader/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl ReaderState {
124124
// We want report error at place where name is expected - this is just
125125
// before `>`
126126
self.offset -= 1;
127-
return Err(Error::IllFormed(IllFormedError::MissedDoctypeName));
127+
return Err(Error::IllFormed(IllFormedError::MissingDoctypeName));
128128
}
129129
}
130130
}
@@ -170,7 +170,7 @@ impl ReaderState {
170170
// Report error at start of the end tag at `<` character
171171
// +2 for `<` and `>`
172172
self.offset -= buf.len() + 2;
173-
return Err(Error::IllFormed(IllFormedError::MismatchedEnd {
173+
return Err(Error::IllFormed(IllFormedError::MismatchedEndTag {
174174
expected,
175175
found: decoder.decode(name).unwrap_or_default().into_owned(),
176176
}));
@@ -183,7 +183,7 @@ impl ReaderState {
183183
// Report error at start of the end tag at `<` character
184184
// +2 for `<` and `>`
185185
self.offset -= buf.len() + 2;
186-
return Err(Error::IllFormed(IllFormedError::UnmatchedEnd(
186+
return Err(Error::IllFormed(IllFormedError::UnmatchedEndTag(
187187
decoder.decode(name).unwrap_or_default().into_owned(),
188188
)));
189189
}

tests/fuzzing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn fuzz_empty_doctype() {
5656
let mut buf = Vec::new();
5757
assert!(matches!(
5858
reader.read_event_into(&mut buf).unwrap_err(),
59-
Error::IllFormed(IllFormedError::MissedDoctypeName)
59+
Error::IllFormed(IllFormedError::MissingDoctypeName)
6060
));
6161
assert_eq!(reader.read_event_into(&mut buf).unwrap(), Event::Eof);
6262
}

tests/issues.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ mod issue514 {
146146
match reader.read_event() {
147147
Err(Error::IllFormed(cause)) => assert_eq!(
148148
cause,
149-
IllFormedError::MismatchedEnd {
149+
IllFormedError::MismatchedEndTag {
150150
expected: "some-tag".into(),
151151
found: "other-tag".into(),
152152
}

tests/reader-config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ mod check_end_names {
330330
match reader.read_event() {
331331
Err(Error::IllFormed(cause)) => assert_eq!(
332332
cause,
333-
IllFormedError::MismatchedEnd {
333+
IllFormedError::MismatchedEndTag {
334334
expected: "tag".into(),
335335
found: "mismatched".into(),
336336
}
@@ -421,7 +421,7 @@ mod trim_markup_names_in_closing_tags {
421421
match reader.read_event() {
422422
Err(Error::IllFormed(cause)) => assert_eq!(
423423
cause,
424-
IllFormedError::MismatchedEnd {
424+
IllFormedError::MismatchedEndTag {
425425
expected: "root".into(),
426426
found: "root \t\r\n".into(),
427427
}

0 commit comments

Comments
 (0)