Skip to content

fix: IP range validation and improved error handling #430

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

famouswizard
Copy link

I have corrected the ranges for both IPv4 and IPv6 to ensure they align with valid address formats.
Additionally, I’ve added a try-except block to better handle exceptions related to incorrect IP values. If an invalid IP is encountered, the error message is now more informative and easier to understand.

Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

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

I'm fine with you adding an error message, but this isn't the way to do it. You're fundamentally changing the exception type of this function, and then adding the now-wrong exception in the docstring.

Comment on lines +12 to +13
:raises: netaddr.core.AddrFormatError: Raised when the passed int_val is
not a valid IP integer value.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the exception raised. You have changed this to a ValueError.

Comment on lines +17 to +18
except netaddr.core.AddrFormatError as e:
raise ValueError(f"Invalid IP integer value: {int_val}") from e
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not change exception raises like this.

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