GithubHelp home page GithubHelp logo

Comments (5)

tkrajina avatar tkrajina commented on May 23, 2024

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.

johnjohndoe avatar johnjohndoe commented on May 23, 2024

@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.

tkrajina avatar tkrajina commented on May 23, 2024

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.

johnjohndoe avatar johnjohndoe commented on May 23, 2024

@tkrajina I disagree. I find it more complicated to handle multiple GPX*Exceptions 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.

johnjohndoe avatar johnjohndoe commented on May 23, 2024

@tkrajina Please consider this comment by abarnert with regards to exception handling.

from gpxpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.