From 14d51e0ebaa4de3f122ec85478002d559245fabc Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 14 Aug 2025 20:26:27 +0200 Subject: [PATCH] more helpful error message for dose_coefficients (#3534) --- openmc/data/effective_dose/dose.py | 7 ++++++- tests/unit_tests/test_data_dose.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/openmc/data/effective_dose/dose.py b/openmc/data/effective_dose/dose.py index c7f458d1c6..d49043b0a6 100644 --- a/openmc/data/effective_dose/dose.py +++ b/openmc/data/effective_dose/dose.py @@ -82,7 +82,12 @@ def dose_coefficients(particle, geometry='AP', data_source='icrp116'): cv.check_value('data_source', data_source, {'icrp74', 'icrp116'}) if (data_source, particle) not in _FILES: - raise ValueError(f"{particle} has no dose data in data source {data_source}.") + available_particles = sorted({p for (ds, p) in _FILES if ds == data_source}) + msg = ( + f"'{particle}' has no dose data in data source {data_source}. " + f"Available particles for {data_source} are: {available_particles}" + ) + raise ValueError(msg) elif (data_source, particle) not in _DOSE_TABLES: _load_dose_icrp(data_source, particle) diff --git a/tests/unit_tests/test_data_dose.py b/tests/unit_tests/test_data_dose.py index 2d80cf8384..4f18800143 100644 --- a/tests/unit_tests/test_data_dose.py +++ b/tests/unit_tests/test_data_dose.py @@ -41,3 +41,23 @@ def test_dose_coefficients(): dose_coefficients('neutron', 'ZZ') with raises(ValueError): dose_coefficients('neutron', data_source='icrp7000') + with raises(ValueError) as excinfo: + dose_coefficients("photons", data_source="icrp116") + expected_particles = [ + "electron", + "helium", + "mu+", + "mu-", + "neutron", + "photon", + "photon kerma", + "pi+", + "pi-", + "positron", + "proton", + ] + expected_msg = ( + "'photons' has no dose data in data source icrp116. " + f"Available particles for icrp116 are: {expected_particles}" + ) + assert str(excinfo.value) == expected_msg