Skip to content

Commit

Permalink
Better error message, avoiding UnicodeDecodeError (cctbx#763)
Browse files Browse the repository at this point in the history
Catch UnicodeDecodeError and raise more appropriate InvalidExperimentListError

Fixes dials/dials#2453
  • Loading branch information
dagewa authored Oct 7, 2024
1 parent 2bde8b8 commit 898072e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions newsfragments/763.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise a more suitable error message when failing to load an experiment list.
11 changes: 8 additions & 3 deletions src/dxtbx/model/experiment_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,14 @@ def from_json_file(filename, check_format=True):
"""Load an experiment list from a json file."""
filename = os.path.abspath(filename)
directory = os.path.dirname(filename)
with open(filename) as infile:
return ExperimentListFactory.from_json(
infile.read(), check_format=check_format, directory=directory
try:
with open(filename) as infile:
return ExperimentListFactory.from_json(
infile.read(), check_format=check_format, directory=directory
)
except UnicodeDecodeError:
raise InvalidExperimentListError(
f"Cannot interpret {filename} as an ExperimentList"
)

@staticmethod
Expand Down

0 comments on commit 898072e

Please sign in to comment.