Skip to content

Commit

Permalink
More specific exception types when raw/proc data not found
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Oct 16, 2024
1 parent 6d15a45 commit 93e4176
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions extra_data/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ def _identify_sources(cls, data, detector_name, modules=None, raw=None):
source_to_modno = dict(cls._source_matches(data, pat))
if not all(cls._data_is_raw(data, s) for s in source_to_modno):
# Older corrected data used the same names as raw
raise Exception("Raw data was requested, but only proc data was found")
raise ValueError(
f"Raw data was not found: {detector_name}/DET/... sources "
f"are from corrected data"
)

else:
# Prefer corrected data
Expand All @@ -282,15 +285,16 @@ def _identify_sources(cls, data, detector_name, modules=None, raw=None):
source_to_modno = dict(cls._source_matches(data, pat))

if (raw is False) and any(cls._data_is_raw(data, s) for s in source_to_modno):
raise Exception("Corrected data was requested, but only raw data was found")
raise SourceNameError(f'{detector_name}/CORR/...')
# raw=None -> legacy behaviour: prefer corrected but allow raw

if modules is not None:
source_to_modno = {s: n for (s, n) in source_to_modno.items()
if n in modules}

if not source_to_modno:
raise SourceNameError(f'{detector_name}/DET/...')
dc = '(DET|CORR)' if raw is None else 'DET' if raw else 'CORR'
raise SourceNameError(f'{detector_name}/{dc}/...')

return source_to_modno

Expand Down

0 comments on commit 93e4176

Please sign in to comment.