Loading…
|
binarycleric |
added meaningful exceptions to IPAddr
…
Previously IPAddr would throw ArgumentError regardless of the cause of the exception. More meaningful exceptions were added (extending ArgumentError for backward compatibility). With new exceptions a developer can pragmatically determine the cause of the IPAddr failure in a more effective manor than checking the exception message. |
006aaa7
|
I like this change, but we need approval from @knu because he is the maintainer. @knu what do you think of this change?
It's annoying to inherit from ArgumentError, but makes sense for backwards compatibility.
I like the basics of the idea. Here's my suggestions.
Error
.IPAddr::Error
(which would inherit ArgumentError
for backwards compatibility).UnsupportedAddressFamily
, InconsistentAddressFamily
, and UnspecifiedAddressFamily
separately. What about just AddressFamilyError
that represents these all?InvalidLength
would be better called InvalidPrefixError
.ZeroFilledNumber
might not be worth being a separate class and could be merged into InvalidIPv4
, or should at least be a subclass of that.@knu Thanks for the suggestions, they all make perfect sense. I try to implement these changes today.
Thanks. On further consideration, I'm going to make the following changes.
When the address families mismatch in mask!
, raise InvalidPrefixError
instead of AddressFamilyError
.
Merge InvalidIPv4Error
and InvalidIPv6Error
into InvalidAddressError
, because you can't easily tell which version of IP address a given malformed IP address string was intended to be when IPAddr.new
accepts both IPv4 and IPv6 addresses. At least the current implementation is not really made for that.
Make InvalidPrefixError
a subclass of InvalidAddressError
because it is caused by a bad network address string.
|
knu |
* lib/ipaddr.rb: Introduce several new error classes where only
…
ArgumentError and StandardError were used. IPAddr::Error is their common ancestor class that inherits from ArgumentError for backward compatibility. Submitted by Jon Daniel. Fixes #173 on GitHub. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e |
e03d266
|
|
knu |
* lib/ipaddr.rb: Introduce several new error classes where only
…
ArgumentError and StandardError were used. IPAddr::Error is their common ancestor class that inherits from ArgumentError for backward compatibility. Submitted by Jon Daniel. Fixes #173 on GitHub. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e |
03c53ec
|
added meaningful exceptions to IPAddr …
Previously IPAddr would throw ArgumentError regardless of the cause of the exception. More meaningful exceptions were added (extending ArgumentError for backward compatibility). With new exceptions a developer can pragmatically determine the cause of the IPAddr failure in a more effective manor than checking the exception message.
At my day job we are doing some processing of an incoming IP address / host name in a Rails middleware and I noticed that the IPAddr class would always raise
ArgumentError
with only the error message giving any clue as to the cause.I needed to be able to programmatically determine to cause of the failure to determine how to procede. Matching against the error message was less than ideal so modifying the Exceptions in seemed to be the most logical course of action.
With new exceptions a developer can pragmatically determine the cause of the IPAddr failure in a more effective manor than checking the exception message.
Previously
With Patch