Comments (5)
Hi @johnjohndoe thanks for your bug submission. I changed and commited a new version. The parse() method will now fail on invalid XML file and the code where your problem was manifesting is deleted. Also, I deleted the is_valid() method (it there is a exception on parse() -- no need to check is_valid() later).
Hope this is OK for you?
from gpxpy.
@tkrajina Looks good so far.
One thing I would rewrite is how you handle exceptions. I would not handle all errors as generic exceptions but add a specific XMLSyntaxError except
block before. This is the error you know of at the point in time.
except XMLSyntaxError as e:
mod_logging.debug('Error in:\n%s\n-----------\n' % self.xml)
mod_logging.exception(e)
raise mod_gpx.GPXException('Error parsing XML: %s' % str(e))
except Exception as e:
mod_logging.debug('Error in:\n%s\n-----------\n' % self.xml)
mod_logging.exception(e)
raise mod_gpx.GPXException('Unknown error: %s' % str(e))
If you can accept a crash on an unknown error you could even omit the generic except
block.
from gpxpy.
What about this: 8accbce ?
The idea is to have two kinds of gpxpy exceptions, one for invalid XML files and the other for invalid valid-XML-invalid-GPX files. You can choose if to detect all exceptions with GPXException or XML-specific with GPXXMLSyntaxException. If GPXXMLSyntaxException -- you can retrieve the original (which can be lxml or minidom) exception with e.original_exception.
from gpxpy.
@tkrajina I disagree. I find it more complicated to handle multiple GPX*Exception
s as a user of the library. What would be the benefit of yet another wrapper for an exception caused by an internal module not part of the library? All the user needs is the original error message which you wrap into a GPXException
. This is good enough imho.
from gpxpy.
@tkrajina Please consider this comment by abarnert with regards to exception handling.
from gpxpy.
Related Issues (20)
- coordinate bounding box HOT 2
- metadata error in bounds HOT 1
- Force stdlib etree instead of lxml? HOT 1
- Uphill Downhill are not accurate HOT 2
- GPX parsing not working with extension HOT 2
- NameError: free variable 'from_start_to_end' referenced before assignment in enclosing scope HOT 1
- Setup.py method is being deprecated in python package
- Confusion!
- Wrong distance? 10.4 km instead of 7.6 km HOT 1
- Save nsmap of GPX in GPXTrack, GPXTrackSegment and GPXTrackPoint
- GPX track all messed up HOT 1
- Tag a release to ship improvements since 1.5.0 HOT 1
- TypeError in gpxfield since 1.6.0 release HOT 1
- Changes Backported To 1.5.0 HOT 2
- Typo in __repr__ of SimpleTZ HOT 1
- [newbie] Wrong return type on GPXTrackSegment.get_duration() HOT 1
- create CI testing scripts HOT 1
- feature request: include distance_from_start in NearestLocationsData class HOT 1
- Is Header malformed
- Check for GPX root node on parse HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpxpy.