question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coroutine implementation throws uncaught exception instead of FuelError

See original GitHub issue

Desired

As a user of the coroutine library I would like to see any server error, or deserialisation error returned to me as part of the result object ( Result<T,FuelError>).

Actual

When a server error is thrown then an uncaught exception is thrown and my app crashes When a deserialisation error is thrown then an uncaught exception is thrown and my app crashes

I believe the the line of code causing this is Coroutines.kt, line 27

I have removed the source code from my gradle and created a local file in which I have tested the following modifications, if you feel it is an improvement I will happily make a pr with the appropriate Unit tests and submit it for review.

private suspend fun <T : Any, U : Deserializable<T>> Request.awaitSafely(
        deserializable: U
): Triple<Request, Response, Result<T, FuelError>> =
        suspendCancellableCoroutine { continuation ->
            continuation.invokeOnCompletion {
                if (continuation.isCancelled) {
                    continuation.cancel()
                }
            }
            continuation.resume(response(deserializable))
        }
...


/**
 * This function catches both server errors and Deserialization Errors
 *
 * @param deserializable
 *
 * @return Result object
 * */
suspend fun <U : Any> Request.awaitResultObject (
        deserializable: ResponseDeserializable<U>
):  Result<U, FuelError> = awaitSafely(deserializable).third

If this is not a suitable solution then could we mark this as a @Throws?

If this is not an issue then please explain what I have done incorrectly. thanks mark

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
markGilchristcommented, Jun 30, 2018

@lucasvalenteds I will do it asap, I have some questions can you email me mark[dot]s[dot]w[dot]gilchrist[at]gmail[dot]com

1reaction
lucasvalentedscommented, Jun 12, 2018

My question was also would it not be better to have deserialisation errors caught in this manner out of the box?

Could you please check the issue #365 and see if it’s what you’re suggesting? At this time I’m waiting response of another user about how to handle exceptions.

If there is any why I can make any contributions then please say

Since it involves design/consistency of the library some maintainer could help with that. @kittinunf Could you take a look, please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exceptions in coroutines. Cancellation and Exceptions in…
If a child coroutine throws an exception, the UI scope will be cancelled and the whole UI component will become unresponsive as a...
Read more >
Coroutine exceptions handling | Kotlin
Here we look at what happens if an exception is thrown during cancellation or multiple children of the same coroutine throw an exception....
Read more >
Coroutines - Fuel - Documentation - GitBook
The difference with these implementations is that they throw exception instead of returning it wrapped a FuelError instance. runBlocking {.
Read more >
Why exception handling with Kotlin Coroutines is so hard and ...
An uncaught exception, instead of being re-thrown, is “propagated up the job hierarchy”. This exception propagation leads to the failure of ...
Read more >
Kotlin coroutine can't handle exception - Stack Overflow
The behavior of your second example is correct, this is the work of structured concurrency. Because the inner async block throws an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found