Include the child tag name into 'InvalidChildElement' error. #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes the error much more useful. Including the actual name of a tag that caused problem makes it possible to figure out what's wrong with the gpx file without having to go through the library code finding out what did it expect.
Full context
I've been trying to parse the gpx track from my Garmin device, but
gpx::read
errored out with:I opened the file and saw the following:
It was my first time looking at GPX and my first time using rust-gpx (also the first time playing with Rust), so I couldn't tell right away which part of that XML is considered invalid. However I saw that the xml schema/namespace references some Garmin's extensions to GPX and thought that it must be what rust-gpx doesn't like.
I had a look at
src/parser/track.rs
and saw that it matches some standard tags, and for any other tag it just returnsInvalidChildElement("track")
throwing away the actual name of "invalid" element.I didn't want to keep eyeballing my file, cross-referencing it with the list of tags expected by
track.rs
. Instead I wanted to actually improve the error message, so I made this patch which makes it produce the following error message:This gives a reference to the unexpected thing and allows to easily find it in the xml file, meaning that if later somebody runs the parser on unsupported gpx file they'll have easier time figuring out the problem and reporting it.
P.S. I'm very much a rust newbie, so any improvement suggestions will be appreciated.
P.P.S. I still want to parse and process my files and also improve the experience of parsing GPX files with third-party extensions, but that'll go into another issue/PR.