Skip to content

Commit a049cd2

Browse files
Mingundralley
andcommitted
Better document Error::XmlDeclWithoutVersion and Error::EmptyDocType
Co-authored-by: Daniel Alley <dalley@redhat.com>
1 parent 53c6b4e commit a049cd2

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/errors.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,24 @@ pub enum Error {
140140
///
141141
/// [`encoding`]: index.html#encoding
142142
NonDecodable(Option<Utf8Error>),
143-
/// `Event::BytesDecl` must start with *version* attribute. Contains the attribute
144-
/// that was found or `None` if an xml declaration doesn't contain attributes.
143+
/// A `version` attribute was not found in an XML declaration or is not the
144+
/// first attribute.
145+
///
146+
/// According to the [specification], the XML declaration (`<?xml ?>`) MUST contain
147+
/// a `version` attribute and it MUST be the first attribute. This error indicates,
148+
/// that the declaration does not contain attributes at all (if contains `None`)
149+
/// or either `version` attribute is not present or not the first attribute in
150+
/// the declaration. In the last case it contains the name of the found attribute.
151+
///
152+
/// [specification]: https://www.w3.org/TR/xml11/#sec-prolog-dtd
145153
XmlDeclWithoutVersion(Option<String>),
146-
/// Empty `Event::DocType`. `<!doctype foo>` is correct but `<!doctype > is not.
154+
/// A document type definition (DTD) does not contain a name of a root element.
155+
///
156+
/// According to the [specification], document type definition (`<!doctype foo>`)
157+
/// MUST contain a name which defines a document type. If that name is missed,
158+
/// this error is returned.
147159
///
148-
/// See <https://www.w3.org/TR/xml11/#NT-doctypedecl>
160+
/// [specification]: https://www.w3.org/TR/xml11/#NT-doctypedecl
149161
EmptyDocType,
150162
/// Attribute parsing error
151163
InvalidAttr(AttrError),
@@ -246,12 +258,16 @@ impl fmt::Display for Error {
246258
Error::IllFormed(e) => write!(f, "ill-formed document: {}", e),
247259
Error::NonDecodable(None) => write!(f, "Malformed input, decoding impossible"),
248260
Error::NonDecodable(Some(e)) => write!(f, "Malformed UTF-8 input: {}", e),
249-
Error::XmlDeclWithoutVersion(e) => write!(
261+
Error::XmlDeclWithoutVersion(None) => {
262+
write!(f, "an XML declaration does not contain `version` attribute")
263+
}
264+
Error::XmlDeclWithoutVersion(Some(attr)) => {
265+
write!(f, "an XML declaration must start with `version` attribute, but in starts with `{}`", attr)
266+
}
267+
Error::EmptyDocType => write!(
250268
f,
251-
"XmlDecl must start with 'version' attribute, found {:?}",
252-
e
269+
"`<!DOCTYPE>` declaration does not contain a name of a document type"
253270
),
254-
Error::EmptyDocType => write!(f, "DOCTYPE declaration must not be empty"),
255271
Error::InvalidAttr(e) => write!(f, "error while parsing attribute: {}", e),
256272
Error::EscapeError(e) => write!(f, "{}", e),
257273
Error::UnknownPrefix(prefix) => {

0 commit comments

Comments
 (0)