-
Notifications
You must be signed in to change notification settings - Fork 16
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
Propagate exceptions occurring during client instantiation #353
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #353 +/- ##
=============================================
+ Coverage 0 48.00% +48.00%
- Complexity 0 501 +501
=============================================
Files 0 137 +137
Lines 0 3704 +3704
Branches 0 242 +242
=============================================
+ Hits 0 1778 +1778
- Misses 0 1734 +1734
- Partials 0 192 +192
|
c47120e
to
ddbae4c
Compare
2a9740a
to
931ed66
Compare
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.
Looks good to me. Sections pointed out by you as debatable should work either way for the time being. :)
@andregasser Do you want to check this yourself as well? Otherwise we could merge this soon. 😊 |
If I could have a quick look at it would be awesome. Will do it today, ok? |
bigbone/src/main/kotlin/social/bigbone/api/exception/BigBoneClientInstantiationException.kt
Show resolved
Hide resolved
Signed-off-by: PattaFeuFeu <code@patrick-geselbracht.eu>
Signed-off-by: PattaFeuFeu <code@patrick-geselbracht.eu>
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.
Please see my other comment.
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.
👍
Description
This PR improves our error handling when instantiating a
MastodonClient
through theBuilder#build
function.This closes #282 which was an issue originally created because we found out in #280 that exceptions were just swallowed without doing anything. This resulted in a user of our library not figuring out easily that they were trying to call network code on a main thread.
The main issue in our client instantiation is that we need to get an instance version to know what we’re dealing with. Whether that’s even the case or if we could restructure our code to no longer need that is a different topic which I did not handle here.
I introduced a few new custom Exception classes which are returned in specific cases where we either cannot get server information, a
NodeInfo
’s URL, or an instance version via the API v2 or v1.I tried to catch only those exceptions that we throw ourselves and not intervene with any more general or other exceptions. This way, I/O exceptions, security exceptions, … should just be propagate uncaught to the caller.
I have kept the double fallback solution for the instance version:
NodeInfoClient
NodeInfoClient
as causes, if possibleType of Change
Breaking Changes
MastodonClient.Builder#build
may now throw aBigBoneClientInstantiationException
.Java clients will no longer be able to build unless they either surround the build call with a try/catch block or add the exception to the method signature of the function calling the builder.How Has This Been Tested?
I have added new unit tests and tried the “Get public timeline” sample with both existing and non-existing Mastodon servers, with an existing Internet connection and without one.
Mandatory Checklist
gradle check
and there were no errors reported