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

Include the child tag name into 'InvalidChildElement' error. #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ error_chain!{
errors {
/// InvalidChildElement signifies when an element has a child that isn't
/// valid per the GPX spec.
InvalidChildElement(parent: &'static str) {
InvalidChildElement(child: String, parent: &'static str) {
description("invalid child element")
display("invalid child element in {}", String::from(*parent))
display("invalid child element '{}' in {}", child, String::from(*parent))
}

/// InvalidElementLacksAttribute signifies when an element is missing a
Expand Down
7 changes: 5 additions & 2 deletions src/parser/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<String> {

email = Some(format!("{id}@{domain}", id = id, domain = domain));
}
_ => Err(Error::from(ErrorKind::InvalidChildElement("email")))?,
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"email",
)))?,
}
}

Expand Down Expand Up @@ -117,7 +120,7 @@ mod tests {
let err = consume!("<email id=\"id\" domain=\"domain\"><child /></email>").unwrap_err();

assert_eq!(err.description(), "invalid child element");
assert_eq!(err.to_string(), "invalid child element in email");
assert_eq!(err.to_string(), "invalid child element 'child' in email");
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion src/parser/gpx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<Gpx> {
"trk" => Ok(ParseEvent::StartTrack),
"wpt" => Ok(ParseEvent::StartWaypoint),
"gpx" => Ok(ParseEvent::Ignore),
_ => Err(Error::from(ErrorKind::InvalidChildElement("gpx")))?,
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"gpx",
)))?,
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/parser/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<Link> {

link.href = attr.value;
}
_ => Err(Error::from(ErrorKind::InvalidChildElement("link")))?,
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"link",
)))?,
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/parser/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<Metadata> {
"keywords" => Ok(ParseEvent::StartKeywords),
"time" => Ok(ParseEvent::StartTime),
"link" => Ok(ParseEvent::StartLink),
_ => Err(Error::from(ErrorKind::InvalidChildElement("metadata")))?,
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"metadata",
)))?,
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/parser/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<Person> {
"link" => Ok(ParseEvent::StartLink),
"person" => Ok(ParseEvent::Ignore),
"author" => Ok(ParseEvent::Ignore),
_ => Err(Error::from(ErrorKind::InvalidChildElement("person"))),
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"person",
))),
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/parser/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<Track> {
"src" => track.source = Some(string::consume(reader)?),
"type" => track._type = Some(string::consume(reader)?),
"trkseg" => track.segments.push(tracksegment::consume(reader)?),
_ => Err(Error::from(ErrorKind::InvalidChildElement("track")))?,
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"track",
)))?,
},

XmlEvent::EndElement { .. } => {
Expand Down
5 changes: 4 additions & 1 deletion src/parser/tracksegment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<TrackSegment
match name.local_name.as_ref() {
"trkseg" => Ok(TrackSegmentEvent::StartTrkSeg),
"trkpt" => Ok(TrackSegmentEvent::StartTrkPt),
_ => Err(Error::from(ErrorKind::InvalidChildElement("tracksegment"))),
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"tracksegment",
))),
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/parser/waypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ pub fn consume<R: Read>(reader: &mut Peekable<Events<R>>) -> Result<Waypoint> {

// Finally the GPX 1.1 extensions
"extensions" => extensions::consume(reader)?,
_ => Err(Error::from(ErrorKind::InvalidChildElement("waypoint")))?,
child => Err(Error::from(ErrorKind::InvalidChildElement(
String::from(child),
"waypoint",
)))?,
}
}

Expand Down