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

Should raise FileNotFoundError sooner #463

Closed
ppinchuk opened this issue Aug 14, 2024 · 1 comment
Closed

Should raise FileNotFoundError sooner #463

ppinchuk opened this issue Aug 14, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ppinchuk
Copy link
Collaborator

In this code:

res_fpath = config.setdefault("res_fpath", None)
if isinstance(res_fpath, str) and '{}' in res_fpath:
for year in range(1998, 2018):
if os.path.exists(res_fpath.format(year)):
break
config["res_fpath"] = res_fpath.format(year)

the hardcoded years lead to this error:

Traceback (most recent call last):
  File "/projects/rev/environments/revruns/lib/python3.11/site-packages/rex/resource.py", line 632, in __init__
    self._h5 = h5py.File(self.h5_file, mode=mode)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/rev/environments/revruns/lib/python3.11/site-packages/h5py/_hl/files.py", line 562, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/rev/environments/revruns/lib/python3.11/site-packages/h5py/_hl/files.py", line 235, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 102, in h5py.h5f.open
FileNotFoundError: [Errno 2] Unable to synchronously open file (unable to open file: name = '/kfs2/pdatasets/WIND/conus/v1.0.0/wtk_conus_2017.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

This is confusing because of course WTK 2017 doesn't exist, and no one input 2017 as a year anywhere in the config.

Probably should use the current calendar year as the upper bound? Or maybe 2100 to support sup3rCC?

In either case, the the break doesn't activate, a FileNotFoundError error should be raised without substituting the year.

@ppinchuk ppinchuk added the bug Something isn't working label Aug 14, 2024
@ppinchuk ppinchuk self-assigned this Aug 14, 2024
@ppinchuk
Copy link
Collaborator Author

Fixed in #464

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant