Summary
src/easyreflectometry/project.py:822-833:
if self.path_json.exists() and overwrite:
...unlink...
try:
...
with open(self.path_json, mode='x') as file: # 'x' = exclusive create
...
except Exception as exception:
print(exception)
With overwrite=False and an existing file, the FileExistsError from mode 'x' is swallowed by the blanket except and the method returns as if it succeeded. The same blanket except turns disk-full, permission, and serialization errors into a stdout line. tests/test_project.py::test_save_as_json_dont_overwrite only checks the mtime is unchanged, so it passes while masking that no error is surfaced.
Related broad excepts in project.py
:568-572 count_datasets_in_file: any corrupt file silently reports 1 dataset.
:592-596 load_all_experiments_from_file: masks the ORSO error, then re-attempts a different loader, obscuring the original cause.
- Error-channel inconsistency across the codebase: mixes
print('ERROR: ...'), warnings.warn, logger, and raises; e.g. remove_material (:797-802) prints and silently does nothing.
Suggested fix
Use 'w' after the explicit unlink (or handle FileExistsError specifically and raise), let unexpected exceptions propagate, and standardize on exceptions + logging instead of print.
Found during deep code review (DEEP_ANALYSIS.md §5.5, §6).
Summary
src/easyreflectometry/project.py:822-833:With
overwrite=Falseand an existing file, theFileExistsErrorfrom mode'x'is swallowed by the blanket except and the method returns as if it succeeded. The same blanket except turns disk-full, permission, and serialization errors into a stdout line.tests/test_project.py::test_save_as_json_dont_overwriteonly checks the mtime is unchanged, so it passes while masking that no error is surfaced.Related broad excepts in project.py
:568-572count_datasets_in_file: any corrupt file silently reports 1 dataset.:592-596load_all_experiments_from_file: masks the ORSO error, then re-attempts a different loader, obscuring the original cause.print('ERROR: ...'),warnings.warn,logger, and raises; e.g.remove_material(:797-802) prints and silently does nothing.Suggested fix
Use
'w'after the explicit unlink (or handleFileExistsErrorspecifically and raise), let unexpected exceptions propagate, and standardize on exceptions + logging instead ofprint.Found during deep code review (DEEP_ANALYSIS.md §5.5, §6).