-
Notifications
You must be signed in to change notification settings - Fork 100
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
fixed throwing behavior in daemonConfig #179
Conversation
@@ -101,6 +101,11 @@ private boolean setUDPAndTCPAddress(@Nullable String addr, boolean ignoreInvalid | |||
boolean result = false; | |||
try { | |||
result = processAddress(addr); | |||
|
|||
if (!result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to check ignoreInvalid
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, because the exception will always be caught and then ignoreInvalid
is checked in the catch block. If you think there's a more idiomatic way of doing this I'd be open to it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah didn't notice it - it's a bit weird to throw and immediately catch an exception. Outside of the try block having this with if (!result && !ignoreInvalid)
throw might be more readable, but it's marginable at best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually just did a bigger refactor and made the processAddress
method void
, and just had it throw instead of return false. IMO this improved readability in both the setUDPandTCPAddress
and processAddress
methods, let me know what you think.
@@ -101,6 +101,11 @@ private boolean setUDPAndTCPAddress(@Nullable String addr, boolean ignoreInvalid | |||
boolean result = false; | |||
try { | |||
result = processAddress(addr); | |||
|
|||
if (!result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah didn't notice it - it's a bit weird to throw and immediately catch an exception. Outside of the try block having this with if (!result && !ignoreInvalid)
throw might be more readable, but it's marginable at best.
Description of changes:
In
DaemonConfiguration
, when setting a custom address for the daemon, the expected behavior is to throw an exception when an invalid address is passed to crash an application at startup if it's trying to configure an invalid address. The current behavior was to only crash if a somewhat invalid address, like0.0.0.1
that's just missing a port, was passed. This fix ensures it crashes on arbitrary invalid strings as well.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.