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

Unhelpful error when likelihood file raises exception #173

Closed
tilmantroester opened this issue Aug 5, 2022 · 1 comment
Closed

Unhelpful error when likelihood file raises exception #173

tilmantroester opened this issue Aug 5, 2022 · 1 comment

Comments

@tilmantroester
Copy link
Contributor

If the .py file raises an exception, the last exception being shown is an ImportError with the name of the likelihood .py file, which obscures the original exception (FileNotFoundError, in this case).

mwe_likelihood.py:

from firecrown.likelihood.gauss_family.gaussian import ConstGaussian

raise FileNotFoundError

likelihood = ConstGaussian()
[output] Output to be read-from/written-into folder '.', with prefix 'cobaya_evaluate_output'
[output] Found existing info files with the requested output prefix: 'cobaya_evaluate_output'
[camb] `camb` module loaded successfully from /Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/camb
[exception handler] ---------------------------------------

Traceback (most recent call last):
  File "/Users/yooken/Research/LSST/dev/firecrown/firecrown/likelihood/likelihood.py", line 96, in load_likelihood
    spec.loader.exec_module(mod)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/yooken/Research/LSST/dev/firecrown/broken_examples/fileerror/mwe_likelihood.py", line 3, in <module>
    raise FileNotFoundError
FileNotFoundError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/bin/cobaya-run", line 8, in <module>
    sys.exit(run_script())
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/cobaya/run.py", line 225, in run_script
    run(info, **arguments.__dict__)
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/cobaya/run.py", line 145, in run
    with Model(updated_info["params"], updated_info["likelihood"],
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/cobaya/model.py", line 237, in __init__
    self.likelihood = LikelihoodCollection(info_likelihood, theory=self.theory,
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/cobaya/likelihood.py", line 262, in __init__
    self.add_instance(name, external(info, packages_path=packages_path,
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/cobaya/likelihood.py", line 89, in __init__
    super().__init__(info, name=name, timing=timing,
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/cobaya/theory.py", line 65, in __init__
    super().__init__(info, name=name, timing=timing,
  File "/Users/yooken/Codes/miniforge3/envs/firecrown/lib/python3.10/site-packages/cobaya/component.py", line 332, in __init__
    self.initialize()
  File "/Users/yooken/Research/LSST/dev/firecrown/firecrown/connector/cobaya/likelihood.py", line 22, in initialize
    self.likelihood = load_likelihood(self.firecrownIni)
  File "/Users/yooken/Research/LSST/dev/firecrown/firecrown/likelihood/likelihood.py", line 98, in load_likelihood
    raise ImportError(f"{e.strerror}: {filename}") from e
ImportError: None: mwe_likelihood.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant