LSSTDESC / firecrown

DESC Cosmology Likelihood Framework
BSD 3-Clause "New" or "Revised" License
29 stars 7 forks source link

Not exactly an installation issue, but related to confusing error messages when running Firecrown for the first time without having set {FIRECROWN_DIR} to point to the correct directory. The final error message seen by the user is distracting from the actual issue. #175

Closed marcpaterno closed 1 year ago

marcpaterno commented 2 years ago

Not exactly an installation issue, but related to confusing error messages when running Firecrown for the first time without having set {FIRECROWN_DIR} to point to the correct directory. The final error message seen by the user is distracting from the actual issue.

Here when running "cobaya-run cobaya_evaluate.yaml" (but apparently also applicable to cosmosis):

<...>

FileNotFoundError: [Errno 2] No such file or directory: '${FIRECROWN_DIR}/examples/des_y1_3x2pt/des_y1_3x2pt_sacc_data.fits'
The above exception was the direct cause of the following exception:

<...>

 File "/Users/agne/opt/anaconda3/envs/fc/lib/python3.10/site-packages/firecrown/likelihood/likelihood.py", line 105, in load_likelihood
    raise ImportError(f"{e.strerror}: {filename}") from e
ImportError: No such file or directory: des_y1_3x2pt.py

Originally posted by @agnesemenaite in https://github.com/LSSTDESC/firecrown/issues/172#issuecomment-1206740158

marcpaterno commented 2 years ago

This is a problem caused by the fact that we have code that can fail being executed at import time. We should change the design of our "factory function" scripts to be instead python modules that declare a factory function (that returns the likelihood object). This will make it easier to detect this kind of failure and to product a meaningful error message.

tilmantroester commented 2 years ago

I think the issue is that FileNotFoundError gets caught and then re-raised as an unhelpful ImportError here: https://github.com/LSSTDESC/firecrown/blob/master/firecrown/likelihood/likelihood.py#L104 See the MWE in the other issue I opened on this: #173 Other exceptions being raised just show up as one would expect, it's just FileNotFoundError (which are very common) that get obfuscated.

vitenti commented 1 year ago

Fixed by PR #207