diff --git a/newsfragments/763.bugfix b/newsfragments/763.bugfix new file mode 100644 index 000000000..d66758c6f --- /dev/null +++ b/newsfragments/763.bugfix @@ -0,0 +1 @@ +Raise a more suitable error message when failing to load an experiment list. diff --git a/src/dxtbx/model/experiment_list.py b/src/dxtbx/model/experiment_list.py index 1720c62e2..9145bcf65 100644 --- a/src/dxtbx/model/experiment_list.py +++ b/src/dxtbx/model/experiment_list.py @@ -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