-
Notifications
You must be signed in to change notification settings - Fork 76
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
chore: handle offline mode more graceful #698
Conversation
if (e.getResponseCode() == -1) { | ||
// no internet connection, do nothing | ||
} else { | ||
e.printStackTrace(); | ||
} |
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.
Hm, PMD says this is bad, and instead we should do
if (e.getResponseCode() == -1) { | |
// no internet connection, do nothing | |
} else { | |
e.printStackTrace(); | |
} | |
if (e.getResponseCode() != -1) { | |
// -1 would indicate no internet connection, in which case the exception is expected | |
// and should just be ignored. In all other cases, this is indeed exceptional behavior | |
// and we print the stacktrace. | |
e.printStackTrace(); | |
} |
I personally prefer the variant with the empty if branch, because I think the reasoning for the control flow is more comprehensible.
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 believe that your variant is fine. I'd say we can add a nopmd comment: https://pmd.github.io/pmd/pmd_userdocs_suppressing_warnings.html#nopmd-comment
The example they give even is an empty if statement 😁
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.
Thanks for adding the //NOPMD
comments 👍
Without this change (offline):
With this change (offline): With this change (online):
|
Contains
Instead of blindly logging the stacktrace of exceptions the launcher now checks for an
HTTPException
and whether the status code is -1, indiciating a network issue, for instance, when running offline.Thus, we should only log in exceptional cases.
This does not affect any functionality of the launcher when run offline, though.
How to test
Start the launcher when offline and observe the logs. There should be less stacktraces printed from the GitHub repository adapter.
Outstanding before merging
Nothing.