Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improve error and warning infrastructure #349

Merged
merged 4 commits into from
Jun 24, 2024

Conversation

tovrstra
Copy link
Member

@tovrstra tovrstra commented Jun 23, 2024

Here is another PR corresponding to two tasks in #191, i.e. to make all warnings and errors consistent with the previous PR that improved the LoadError logic: #345. It was difficult to split this up in one PR per error or warning class because they make use of the same machinery.

Main improvements:

Related points deferred to later pull requests:

  • Update of the dump_* sections in CONTRIBUTING.md. This will be done after the prepare_dump API has been completed.

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

Summary by Sourcery

This pull request improves the error and warning infrastructure by standardizing messages to include file and line number information, introducing base classes for file-related errors and warnings, and refactoring functions to handle warnings more effectively. It also updates the prepare_dump function signatures and adds tests for the new warning behaviors.

  • Enhancements:
    • Standardized error and warning messages to include file and line number information where relevant.
    • Introduced a base class for file-related errors and warnings to streamline error handling.
    • Updated the prepare_dump function signatures to include the filename parameter for better error context.
    • Implemented a decorator to correct the stack level of warnings raised in deeper function calls.
    • Refactored the LineIterator class to remove the warn method and handle warnings directly using the warn function.
  • Tests:
    • Added tests to ensure warnings are raised correctly when loading files with unrecognized elements or bond types.

Copy link
Contributor

sourcery-ai bot commented Jun 23, 2024

Reviewer's Guide by Sourcery

This pull request improves the error and warning infrastructure by making all warnings and errors consistent with the previous PR that improved the 'LoadError' logic. Key changes include adding 'filename' parameters to various functions for better error messages, replacing 'warn' calls with 'LoadWarning' instances, and introducing helper functions and base classes for errors and warnings. Additionally, the '_reissue_warnings' decorator was applied to several API functions to correct the stacklevel of warnings.

File-Level Changes

Files Changes
iodata/formats/json.py
iodata/formats/molden.py
iodata/formats/wfx.py
iodata/formats/pdb.py
iodata/formats/molekel.py
iodata/formats/wfn.py
iodata/formats/fchk.py
iodata/formats/mol2.py
Updated various functions to include 'filename' parameter for error messages and replaced 'warn' calls with 'LoadWarning' instances.
iodata/utils.py
iodata/api.py
Introduced helper functions and base classes for errors and warnings, and applied '_reissue_warnings' decorator to API functions.
iodata/test/test_mol2.py
iodata/test/test_iodata.py
Added tests for new warning and error handling logic.

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:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

deepsource-io bot commented Jun 23, 2024

Here's the code health analysis summary for commits b5bccd9..fd0f2ea. 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.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tovrstra - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 Complexity: 1 issue found
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

iodata/formats/json.py Show resolved Hide resolved
iodata/test/test_mol2.py Outdated Show resolved Hide resolved
iodata/test/test_iodata.py Show resolved Hide resolved
CONTRIBUTING.rst Outdated Show resolved Hide resolved
iodata/formats/wfn.py Show resolved Hide resolved
PaulWAyers
PaulWAyers previously approved these changes Jun 23, 2024
Copy link
Member

@PaulWAyers PaulWAyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just skimmed it but I think you can merge it after a final read-through, Toon.

@tovrstra
Copy link
Member Author

Thanks for reviewing, Paul. I've gone through it and spotted some very minor things. I'll merge right away.

@tovrstra tovrstra merged commit e4efb2e into theochem:main Jun 24, 2024
12 checks passed
@tovrstra tovrstra deleted the informative-warnings-errors branch June 24, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants