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

fixed throwing behavior in daemonConfig #179

Merged
merged 6 commits into from
Jul 15, 2020

Conversation

willarmiros
Copy link
Contributor

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, like 0.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.

@@ -101,6 +101,11 @@ private boolean setUDPAndTCPAddress(@Nullable String addr, boolean ignoreInvalid
boolean result = false;
try {
result = processAddress(addr);

if (!result) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

@willarmiros willarmiros merged commit 48f9b13 into aws:master Jul 15, 2020
@willarmiros willarmiros deleted the daemon-config branch July 15, 2020 17:12
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