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

XSEED Parser: better error message when trying to read a file that does not exist #3312

Merged
merged 1 commit into from Jun 20, 2023

Conversation

megies
Copy link
Member

@megies megies commented Jun 16, 2023

What does this PR do?

Shows a better error message when trying to read a local file with XSEED Parser but that path is not existing actually (e.g. mistyped filename etc).

The logic is quite convoluted and lots of different inputs are allowed of type str/bytes, so at the time the error gets raised it isn't immediately obvious if the input actually was a filename or not, so this is kind of a middle way to improve the message.

In [1]: from obspy.io.xseed import Parser
   ...: 
   ...: dlseedpath = '/home/code/my_dlseedfile.dlseed'
   ...: 
   ...: parser = Parser(dlseedpath)
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Input In [1], in <cell line: 5>()
      1 from obspy.io.xseed import Parser
      3 dlseedpath = '/home/code/my_dlseedfile.dlseed'
----> 5 parser = Parser(dlseedpath)

File ~/git/obspy/obspy/io/xseed/parser.py:119, in Parser.__init__(self, data, debug, strict, compact)
    117 # if a file name is given, read it directly to the parser object
    118 if data:
--> 119     self.read(data)

File ~/miniconda3/envs/master/lib/python3.10/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
    230 if not kwsyntax:
    231     args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File ~/git/obspy/obspy/core/util/decorator.py:298, in map_example_filename.<locals>._map_example_filename(func, *args, **kwargs)
    296                 except IOError:
    297                     pass
--> 298 return func(*args, **kwargs)

File ~/git/obspy/obspy/io/xseed/parser.py:241, in Parser.read(self, data)
    238 if potential_filename_provided is not None \
    239         and not os.path.exists(potential_filename_provided):
    240     msg += '. If a filename was provided, the file does not exist.'
--> 241 raise IOError(msg)

OSError: First byte of data must be in [0-9<]. If a filename was provided, the file does not exist.

Why was it initiated? Any relevant Issues?

fixes #2686

PR Checklist

  • Correct base branch selected? master for new features, maintenance_... for bug fixes
  • This PR is not directly related to an existing issue (which has no PR yet).
  • While the PR is still work-in-progress, the no_ci label can be added to skip CI builds
  • If the PR is making changes to documentation, docs pages can be built automatically.
    Just add the build_docs tag to this PR.
    Docs will be served at docs.obspy.org/pr/{branch_name} (do not use master branch).
    Please post a link to the relevant piece of documentation.
  • If all tests including network modules (e.g. clients.fdsn) should be tested for the PR,
    just add the test_network tag to this PR.
  • All tests still pass.
  • Any new features or fixed regressions are covered via new tests.
  • Any new or changed features are fully documented.
  • Significant changes have been added to CHANGELOG.txt .
  • First time contributors have added your name to CONTRIBUTORS.txt .
  • If the changes affect any plotting functions you have checked that the plots
    from all the CI builds look correct. Add the "upload_plots" tag so that plotting
    outputs are attached as artifacts.
  • New modules, add the module to CODEOWNERS with your github handle
  • Add the yellow ready for review label when you are ready for the PR to be reviewed.

@megies megies added this to the 1.5.0 milestone Jun 16, 2023
@megies megies added the ready for review PRs that are ready to be reviewed to get marked ready to merge label Jun 16, 2023
@megies megies merged commit 6f18a18 into master Jun 20, 2023
26 checks passed
@megies megies deleted the fix_parser_not_a_file branch June 20, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.io.xseed ready for review PRs that are ready to be reviewed to get marked ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xseed Parser: Misleading error message when trying to read non existent filename path
1 participant