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

chore: handle offline mode more graceful #698

Merged
merged 3 commits into from
Jun 30, 2023

Conversation

skaldarnar
Copy link
Member

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.

@skaldarnar skaldarnar added this to the v4.8.0 milestone Jun 30, 2023
@skaldarnar skaldarnar added Status: Actionable An issue or task that can immediately be worked on Type: Maintenance Maintenance or chores not adding new features or fixing bugs. labels Jun 30, 2023
Comment on lines 45 to 49
if (e.getResponseCode() == -1) {
// no internet connection, do nothing
} else {
e.printStackTrace();
}
Copy link
Member Author

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

Suggested change
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.

Copy link
Member

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 😁

Copy link
Member Author

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 👍

@jdrueckert
Copy link
Member

Without this change (offline):
no GithubRepositoryAdapter logs, but

[...]
org.kohsuke.github.HttpException: Server returned HTTP response code: -1, message: 'null' for URL: https://github.com/gitapi/rate_limit
[...]
org.kohsuke.github.HttpException: Server returned HTTP response code: -1, message: 'null' for URL: https://github.com/gitapi/repos/MovingBlocks/Terasology
[...]

With this change (offline):
no GithubRepositoryAdapter logs and no org.kohsuke.github.HttpExceptions

With this change (online):

[...]
20:06:03.983 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/v4.1.0-rc.2: Missing game asset.
20:06:03.984 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/playtestSept2020: Invalid version (no major version): playtestSept2020
20:06:03.984 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/alpha16rc1: Invalid version (no major version): alpha16rc1
20:06:03.985 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/alpha13rc3: Invalid version (no major version): alpha13rc3
20:06:03.985 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/alpha13rc2: Invalid version (no major version): alpha13rc2
20:06:03.985 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/alpha13rc1: Invalid version (no major version): alpha13rc1
20:06:03.986 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/omega994: Invalid version (no major version): omega994
20:06:03.987 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/omega583: Invalid version (no major version): omega583
20:06:03.989 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable55: Invalid version (no major version): stable55
20:06:03.989 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable53: Invalid version (no major version): stable53
20:06:03.989 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable50: Invalid version (no major version): stable50
20:06:03.989 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable49: Invalid version (no major version): stable49
20:06:03.989 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable48: Invalid version (no major version): stable48
20:06:03.990 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable47: Invalid version (no major version): stable47
20:06:03.990 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable46: Invalid version (no major version): stable46
20:06:03.990 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable45: Invalid version (no major version): stable45
20:06:03.990 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable44: Invalid version (no major version): stable44
20:06:03.990 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable42: Invalid version (no major version): stable42
20:06:03.990 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable41: Invalid version (no major version): stable41
20:06:03.990 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable39: Invalid version (no major version): stable39
20:06:03.991 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable38: Invalid version (no major version): stable38
20:06:03.991 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable37: Invalid version (no major version): stable37
20:06:03.991 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable32: Invalid version (no major version): stable32
20:06:03.991 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable31: Invalid version (no major version): stable31
20:06:03.991 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable30: Invalid version (no major version): stable30
20:06:03.991 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/highlight23: Invalid version (no major version): highlight23
20:06:03.992 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/stable29: Invalid version (no major version): stable29
20:06:03.992 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/untagged-9f0b44a85a06aea32eab: Invalid version (no major version): untagged-9f0b44a85a06aea32eab
20:06:03.992 [Launcher init thread] INFO  o.t.l.r.GithubRepositoryAdapter - Could not create game release from Github release https://github.com/MovingBlocks/Terasology/releases/tag/untagged-4b29ff9040aad554a2b6: Invalid version (no major version): untagged-4b29ff9040aad554a2b6
20:06:04.019 [Launcher init thread] DEBUG o.t.l.r.GithubRepositoryAdapter - Github rate limit: GHRateLimit {core {remaining=54, limit=60, resetDate=Fri Jun 30 21:06:01 CEST 2023}, search {remaining=10, limit=10, resetDate=Fri Jun 30 20:07:04 CEST 2023}, graphql {remaining=0, limit=0, resetDate=Fri Jun 30 21:06:04 CEST 2023}, integrationManifest {remaining=5000, limit=5000, resetDate=Fri Jun 30 21:06:04 CEST 2023}}
[...]

@skaldarnar skaldarnar merged commit f3c9f4a into master Jun 30, 2023
@skaldarnar skaldarnar deleted the chore/less-warnings-when-offline branch June 30, 2023 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Actionable An issue or task that can immediately be worked on Type: Maintenance Maintenance or chores not adding new features or fixing bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants