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

fix read_inventory() with invalid filename showing strange error message #2062

Merged
merged 4 commits into from Feb 28, 2018

Conversation

Projects
None yet
2 participants
@megies
Copy link
Member

commented Feb 1, 2018

read_inventory() with invalid filename shows strange error message by lxml..

We should show the usual error messages on Python2/3 instead.

read_inventory("bladfdfdfdfdfd")
IOError                                   Traceback (most recent call last)
<ipython-input-7-35b65229f0b3> in <module>()
----> 1 read_inventory("bladfdfdfdfdfd")

<decorator-gen-158> in read_inventory(path_or_file_object, format, *args, **kwargs)

/home/megies/anaconda/envs/1.1.0py2/lib/python2.7/site-packages/obspy/core/util/decorator.pyc in _map_example_filename(func, *args, **kwargs)
    299                         except IOError:
    300                             pass
--> 301         return func(*args, **kwargs)
    302     return _map_example_filename
    303 

/home/megies/anaconda/envs/1.1.0py2/lib/python2.7/site-packages/obspy/core/inventory/inventory.pyc in read_inventory(path_or_file_object, format, *args, **kwargs)
     96             return read_inventory(fh.name, format=format)
     97     return _read_from_plugin("inventory", path_or_file_object,
---> 98                              format=format, *args, **kwargs)[0]
     99 
    100 

/home/megies/anaconda/envs/1.1.0py2/lib/python2.7/site-packages/obspy/core/util/base.pyc in _read_from_plugin(plugin_type, filename, format, **kwargs)
    384                 position = None
    385             # check format
--> 386             is_format = is_format(filename)
    387             if position is not None:
    388                 filename.seek(0, 0)

/home/megies/anaconda/envs/1.1.0py2/lib/python2.7/site-packages/obspy/io/stationxml/core.pyc in _is_stationxml(path_or_file_object)
     66         else:
     67             try:
---> 68                 xmldoc = etree.parse(path_or_file_object)
     69             except etree.XMLSyntaxError:
     70                 return False

src/lxml/etree.pyx in lxml.etree.parse (src/lxml/etree.c:83185)()

src/lxml/parser.pxi in lxml.etree._parseDocument (src/lxml/etree.c:120757)()

src/lxml/parser.pxi in lxml.etree._parseDocumentFromURL (src/lxml/etree.c:121104)()

src/lxml/parser.pxi in lxml.etree._parseDocFromFile (src/lxml/etree.c:120012)()

src/lxml/parser.pxi in lxml.etree._BaseParser._parseDocFromFile (src/lxml/etree.c:114561)()

src/lxml/parser.pxi in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/etree.c:107738)()

src/lxml/parser.pxi in lxml.etree._handleParseResult (src/lxml/etree.c:109447)()

src/lxml/parser.pxi in lxml.etree._raiseParseError (src/lxml/etree.c:108258)()

IOError: Error reading file 'bladfdfdfdfdfd': failed to load external entity "bladfdfdfdfdfd"

add failing test that shows strange message when trying read_inventory()
with invalid filenames (lxml shows strange error message in these cases)

@megies megies added this to the 1.1.1 milestone Feb 1, 2018

@megies megies self-assigned this Feb 1, 2018

megies added some commits Feb 1, 2018

@@ -13,7 +13,6 @@
unicode_literals)
from future.builtins import * # NOQA
from future.utils import python_2_unicode_compatible, native_str

import copy

This comment has been minimized.

Copy link
@megies

megies Feb 2, 2018

Author Member

will add this empty line again.. was accidentally deleted

@megies megies added the ready label Feb 2, 2018

@megies megies force-pushed the fix_read_inv_wrong_filename branch from b1448d1 to a3934fa Feb 2, 2018

@megies

This comment has been minimized.

Copy link
Member Author

commented Feb 2, 2018

IMHO ready for merging..

@Jollyfant
Copy link
Contributor

left a comment

Includes big test coverage for a minor change. if CI passes it's all good.

continue
break
else:
self.fail('unable to get invalid file path')

This comment has been minimized.

Copy link
@Jollyfant

Jollyfant Feb 2, 2018

Contributor

Should say: "Reading this message means you should probably stop calling your files dsfhjkfsdsfhjkfsdsfhjkfsdsfhjkfsdsfhjkfsdsfhjkfsdsfhjkfsdsfhjkfsdsfhjkfsdsfhjkfs" 😃

@megies megies merged commit 29c96d4 into maintenance_1.1.x Feb 28, 2018

4 of 6 checks passed

codecov/patch 87.67% of diff hit (target 90%)
Details
docker-testbot docker testbot results not available yet
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 88.07% (+1.2%) compared to 533c7a1
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@megies megies deleted the fix_read_inv_wrong_filename branch Feb 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.