CDAT / cdms

8 stars 10 forks source link

Simplify the error message, when opening a non existing nc file #409

Closed jypeter closed 4 years ago

jypeter commented 4 years ago

Using cdms 3.0.0 of CDAT 8.1

The long traceback you get when you try to open a non existing nc file is a bit confusing. Is there a way to display a simple and straightforward File not found error?

It's all the more confusing because the long traceback is not the same if you use python2 or python3! The python3 version adds aOSError: Variable not found message!

Python2 case

>>> f = cdms2.open('not_found.nc')
CDMS system error: No such file or directory
CDMS I/O error: Opening file /home/scratch01/jypeter/cdms2_bug_data/not_found.nc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py2/lib/python2.7/site-packages/cdms2/dataset.py", line 499, in openDataset
    return CdmsFile(path, mode, mpiBarrier=CdMpi)
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py2/lib/python2.7/site-packages/cdms2/dataset.py", line 1283, in __init__
    raise CDMSError('Cannot open file %s (%s)' % (path, err))
cdms2.error.CDMSError: Cannot open file /home/scratch01/jypeter/cdms2_bug_data/not_found.nc (No error)
>>>

Python3 case

>>> f = cdms2.open('not_found.nc')
CDMS system error: No such file or directory
CDMS I/O error: Opening file /home/users/jypeter/CDAT/Progs/Devel/masa/PMIP4_Sandy/not_found.nc
Traceback (most recent call last):
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py3/lib/python3.6/site-packages/cdms2/dataset.py", line 1281, in __init__
    _fileobj_ = Cdunif.CdunifFile(path, mode)
OSError: Variable not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py3/lib/python3.6/site-packages/cdms2/dataset.py", line 499, in openDataset
    return CdmsFile(path, mode, mpiBarrier=CdMpi)
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py3/lib/python3.6/site-packages/cdms2/dataset.py", line 1283, in __init__
    raise CDMSError('Cannot open file %s (%s)' % (path, err))
cdms2.error.CDMSError: Cannot open file /home/users/jypeter/CDAT/Progs/Devel/masa/PMIP4_Sandy/not_found.nc (Variable not found)
jasonb5 commented 4 years ago

@jypeter Thanks for reporting this.

The python 3 error is indeed off, I'll need to look into what's causing OSError: Variable not found.

CDMS system error: No such file or directory
CDMS I/O error: Opening file /home/users/jypeter/CDAT/Progs/Devel/masa/PMIP4_Sandy/not_found.nc

These verbose messages are coming from another library, I'll look into getting those silenced as they're not very helpful either.

To silence the error and traceback we'd recommend wrapping cdms2.open(...) in a try/catch, this would suppress those.

jypeter commented 4 years ago

Thanks @jasonb5 ! I see you've started working on it