theochem / iodata

Python library for reading, writing, and converting computational chemistry file formats and generating input files.
https://iodata.readthedocs.io/
GNU Lesser General Public License v3.0
133 stars 46 forks source link

Clean up exceptions and split FileFormatError in LoadError and DumpError #345

Closed tovrstra closed 5 months ago

tovrstra commented 5 months ago

This fixes a task in #191: splitting FileFormatError and FileFormatWarning into Load... and Dump... versions, and fix formats that raise various generic exceptions. There is still a FileFormatError, but it is only used for errors related to identifying or selecting the correct file format. This fix will make error messages more informative in general, and it will make the original goal of #191 easier to achieve.

Note that there are a few more tasks related to exception handling in #191, not included in this PR, to keep it small. Cleanups like these quickly become large, so I've suppressed the usual oh-I-can-also-fix-this reflex and deferred these to future PRs instead.

I will YOLO-merge this on June 28 unless reviewed earlier.

Summary by Sourcery

Refactored exception handling to provide more specific error types for loading and dumping operations, and updated corresponding test cases.

sourcery-ai[bot] commented 5 months ago

Reviewer's Guide by Sourcery

This pull request addresses a task from issue #191 by splitting the FileFormatError and FileFormatWarning into more specific LoadError, LoadWarning, DumpError, and DumpWarning classes. The changes aim to make error messages more informative and specific to the context of loading or dumping data. The FileFormatError is retained but is now only used for errors related to identifying or selecting the correct file format. The changes also include updating the exception handling in various modules and tests to use the new error classes.

File-Level Changes

Files Changes
iodata/formats/json.py
iodata/api.py
iodata/utils.py
iodata/test/test_json.py
iodata/formats/mwfn.py
iodata/test/test_cp2klog.py
iodata/formats/pdb.py
iodata/test/test_pdb.py
iodata/formats/gromacs.py
iodata/formats/fchk.py
iodata/formats/mol2.py
iodata/formats/molden.py
iodata/formats/molekel.py
iodata/test/common.py
iodata/test/test_wfx.py
iodata/test/test_api.py
iodata/test/test_inputs.py
iodata/test/test_sdf.py
iodata/formats/gamess.py
iodata/formats/gaussianinput.py
iodata/test/test_mol2.py
Replaced FileFormatError and FileFormatWarning with more specific LoadError, LoadWarning, DumpError, and DumpWarning classes. Updated exception handling in various modules and tests to use the new error classes.

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - You can change your review settings at any time by accessing your [dashboard](https://sourcery.ai/dashboard): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.
deepsource-io[bot] commented 5 months ago

Here's the code health analysis summary for commits 3f2e4fc..cfbbceb. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Shell LogoShell✅ SuccessView Check ↗
DeepSource Python LogoPython✅ Success
🎯 2 occurences resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.
tovrstra commented 5 months ago

Thanks for checking, Paul.

I've also double-checked it, but could not spot obvious mistakes. The critical parts will be revisited in future pull requests, so I'll be taking a second look in any case.