John O'Reilly
08/08/2024, 3:50 PMFetchPolicy.CacheAndNetwork
in both cases. Is there anything else you'd recommend checking to help diagnose? Also if I use CacheOnly
as a test then the data is coming back.John O'Reilly
08/08/2024, 3:51 PMbod
08/08/2024, 3:52 PMJohn O'Reilly
08/08/2024, 3:54 PMJohn O'Reilly
08/08/2024, 3:56 PMCacheOnly
it seems that wouldn't be the issue?bod
08/08/2024, 3:57 PMbod
08/08/2024, 3:59 PMCacheAndNetwork
should always emit twice, are you saying you only get 1 emission in the 2nd case?toFlowV3
)John O'Reilly
08/08/2024, 4:00 PMJohn O'Reilly
08/08/2024, 4:01 PMJohn O'Reilly
08/08/2024, 4:02 PMtoFlowV3
btw fwiwbod
08/08/2024, 4:02 PMJohn O'Reilly
08/08/2024, 4:02 PMJohn O'Reilly
08/08/2024, 4:03 PMtoFlow
but will confirm again (know there's difference in exception logic between them)John O'Reilly
08/08/2024, 4:18 PMdoNotStore(false)
in query fwiw (but being used in both cases as well)bod
08/08/2024, 4:19 PMJohn O'Reilly
08/08/2024, 4:19 PMbod
08/08/2024, 4:20 PMdoNotStore(false)
is the same as not setting anythingbod
08/08/2024, 4:20 PMJohn O'Reilly
08/08/2024, 4:37 PMJohn O'Reilly
08/08/2024, 4:37 PMbod
08/08/2024, 4:40 PMApolloClient.Builder.logCacheMisses(...)
that may help troubleshootbod
08/08/2024, 4:42 PMJohn O'Reilly
08/08/2024, 4:42 PMbod
08/08/2024, 4:42 PMJohn O'Reilly
08/08/2024, 4:44 PMJohn O'Reilly
08/08/2024, 5:01 PMtoFlow()
(with associated update in error handling)!bod
08/08/2024, 5:04 PMtoFlowV3
thoughJohn O'Reilly
08/08/2024, 5:12 PMDefaultApolloException
(and, if so, what would it indicate?)bod
08/08/2024, 5:16 PMJohn O'Reilly
08/08/2024, 5:39 PMJohn O'Reilly
08/08/2024, 5:42 PMdataAssertNoErrors
and then catching DefaultApolloException
that that throwsbod
08/08/2024, 5:42 PM.exception
but they still will be CacheMissException
John O'Reilly
08/08/2024, 5:43 PMdataAssertNoErrors
also check exception
bod
08/08/2024, 5:44 PMdataAssertNoErrors
is one way to goJohn O'Reilly
08/08/2024, 5:44 PMcause
in thatJohn O'Reilly
08/08/2024, 5:44 PMCacheMissException
in this caseJohn O'Reilly
08/13/2024, 10:33 AMtoFlowV3
until some related error response handling changes are made. I think we can reproduce pretty reliably so can perhaps add/capture some extra logging? cc @Marco Pieruccibod
08/13/2024, 12:36 PMJohn O'Reilly
08/13/2024, 12:47 PMJohn O'Reilly
08/13/2024, 1:27 PMtoFlowV3().map
block (or associated collect
)
emit(cacheResponse.newBuilder().isLast(false).build())
bod
08/13/2024, 1:34 PMcacheResponse
have data (no exception)?John O'Reilly
08/13/2024, 1:35 PMJohn O'Reilly
08/13/2024, 1:35 PMJohn O'Reilly
08/13/2024, 3:43 PMJohn O'Reilly
08/13/2024, 3:48 PMbod
08/13/2024, 4:01 PMtoFlowV3
2 queries in parallel, both with CacheAndNetwork
, both are cached, while the networks is down?John O'Reilly
08/13/2024, 4:18 PMtoFlow
....bod
08/13/2024, 4:19 PMJohn O'Reilly
08/13/2024, 4:43 PMApolloNeworkException
(with toFlowV3)?bod
08/13/2024, 4:44 PMbod
08/13/2024, 4:45 PMtry {
apolloClient.query(LaunchListQuery()).fetchPolicy(FetchPolicy.CacheAndNetwork).toFlowV3().collect {
println("0 " + (it.data != null))
}
} catch (e: Exception) {
println("0 " + e)
}
GlobalScope.launch {
try {
apolloClient.query(LaunchListQuery()).fetchPolicy(FetchPolicy.CacheAndNetwork).toFlowV3().collect {
println("1 " + (it.data != null))
}
} catch (e: Exception) {
println("1 " + e)
}
}
This prints:
0 true
0 com.apollographql.apollo.exception.ApolloNetworkException: Failed to execute GraphQL http network request
1 true
1 com.apollographql.apollo.exception.ApolloNetworkException: Failed to execute GraphQL http network request
John O'Reilly
08/13/2024, 4:50 PMJohn O'Reilly
08/13/2024, 5:19 PMMarco Pierucci
08/13/2024, 5:19 PMcorrect. But the exception is thrown so this would interrupt your collectYeah thats the issue we have for replacing toFlowV3 π
John O'Reilly
08/13/2024, 5:32 PMwithContext
in those functions that were invoking the queries seems to have "fixed" the issue here (while still using toFlowV3)bod
08/13/2024, 5:34 PMbod
08/13/2024, 5:35 PMJohn O'Reilly
08/13/2024, 5:35 PMJohn O'Reilly
08/14/2024, 6:10 PMCacheMissedException
) but wihtout being able to reproduce here I haven't been able to confirm (am going to add more logging). Wondering if it could be related to following https://github.com/apollographql/apollo-kotlin/issues/5076John O'Reilly
08/14/2024, 6:12 PMJohn O'Reilly
08/14/2024, 6:13 PMMarco Pierucci
08/14/2024, 6:39 PMJohn O'Reilly
08/14/2024, 7:38 PMApolloCompositeException
still btw.....wonder if any potential implications around use of that (though still using toFlowV3
) ...along with use of response.dataAssertNoErrors
John O'Reilly
08/14/2024, 7:53 PMApolloNetworkException
(and cache data not returned)John O'Reilly
08/15/2024, 1:51 PMJohn O'Reilly
08/15/2024, 1:51 PMMainActivity
and StarWarsRepository
John O'Reilly
08/15/2024, 1:53 PMJohn O'Reilly
08/15/2024, 1:55 PMJohn O'Reilly
08/15/2024, 2:00 PMtoFlowV3
Marco Pierucci
08/15/2024, 5:32 PM@CacheAndNetworkFlowExceptions
fun <D : Operation.Data> ApolloCall<D>.toFlowWithKrakenFieldException(): Flow<D> {
return toFlowV3()
.map { response ->
response.errors?.takeIf { it.isNotEmpty() }?.let { errors ->
throw if (errors.containsAuthError()) {
UnauthorizedException()
} else {
val message = errors.joinToString { it.message }
KrakenFieldClientException(message)
}
} ?: response.dataAssertNoErrors
}.catch { exception ->
throw when (exception) {
is ApolloCompositeException -> {
val cacheMissed =
exception.suppressedExceptions.any { it is CacheMissException }
if (cacheMissed) {
KrakenFieldCacheMissedException(cause = exception)
} else {
wrapNetworkException(exception)
}
}
else -> wrapNetworkException(exception)
}
}
}
So.. something I managed to notice, is that when we see the error executing with our extensions, We some times get the ApolloNetworkException but its not intercepted by our catch ( I actually had a logger there and nothing showed up)
Im not super versed in coroutines, but could it be there something toFlowV3
that bubbles up an exception ?
Funny thing that this behaviour is intermittent at bestJohn O'Reilly
08/16/2024, 8:03 AMmbonnin
08/16/2024, 8:05 AMApolloNetworkException
is not caught by catch{}
on the Flow?mbonnin
08/16/2024, 8:05 AMJohn O'Reilly
08/16/2024, 8:07 AMmbonnin
08/16/2024, 8:08 AMJohn O'Reilly
08/16/2024, 8:08 AMmbonnin
08/16/2024, 8:09 AMmbonnin
08/16/2024, 8:17 AMmbonnin
08/16/2024, 8:21 AM2024-08-16 10:20:27.942 16376-16376 System.out dev.johnoreilly.starwars.androidApp I JFOR: collectPeopleInfo, Data ...
2024-08-16 10:20:27.948 16376-16376 System.out dev.johnoreilly.starwars.androidApp I JFOR: collectPeopleInfo, Exception ...
2024-08-16 10:20:27.956 16376-16376 System.out dev.johnoreilly.starwars.androidApp I JFOR: collectFilmInfo, Exception ...
mbonnin
08/16/2024, 8:21 AMJohn O'Reilly
08/16/2024, 8:23 AMJohn O'Reilly
08/16/2024, 8:24 AMmbonnin
08/16/2024, 8:28 AMmbonnin
08/16/2024, 8:43 AMJohn O'Reilly
08/16/2024, 8:48 AMmbonnin
08/16/2024, 8:50 AMmbonnin
08/16/2024, 8:50 AMJohn O'Reilly
08/16/2024, 8:51 AMJohn O'Reilly
08/16/2024, 8:52 AMmbonnin
08/16/2024, 8:52 AMmbonnin
08/16/2024, 8:52 AMemit
is called but not received looks likeJohn O'Reilly
08/16/2024, 8:53 AMmbonnin
08/16/2024, 8:53 AMmbonnin
08/16/2024, 8:55 AMmbonnin
08/16/2024, 8:56 AMJohn O'Reilly
08/16/2024, 9:01 AMtoFlowV3
for some reason....mbonnin
08/16/2024, 9:01 AMJohn O'Reilly
08/16/2024, 9:02 AMJohn O'Reilly
08/16/2024, 9:02 AMmbonnin
08/16/2024, 9:03 AMtoFlowV3
, the flow throws before it is collected on the UI side?John O'Reilly
08/16/2024, 9:05 AMtoFlow
soon but probably good to understand cause anywaymbonnin
08/16/2024, 9:10 AMchannelFlow
involved. What happens if the channelFlow
throws and there are still elements in the channel?mbonnin
08/16/2024, 9:11 AMmbonnin
08/16/2024, 9:23 AMval flow = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
channelFlow {
send(0)
send(1)
send(2)
}.onEach {
if (it == 2) {
throw Exception("ouille")
}
}
}
flow.catch {
println("exception")
}.collect {
println("got $it")
delay(1000)
}
mbonnin
08/16/2024, 9:23 AMgot 0
got 1
exception
mbonnin
08/16/2024, 9:23 AMJohn O'Reilly
08/16/2024, 9:44 AMJohn O'Reilly
08/16/2024, 9:45 AMtoFlow
)Marco Pierucci
08/16/2024, 10:32 AM(but again don't seem to be seeing issue with v4 andI think this is basically because we moved away from throwing in favor of forwarding)toFlow
Result
sMarco Pierucci
08/16/2024, 1:33 PMtoFlow
from apollov4 and not throwing anymore ( forwarding exceptions from in exception
field or custom exceptions from the errors
field in the form of Result<D>
)mbonnin
08/16/2024, 5:51 PMtoFlow()
is the path forward π . I spent a bit of time with the reproducer this afternoon but Iβm still not 100% clear what the issue is. If anything Iβm confused at how channelFlow {}
should handle errors π€mbonnin
08/16/2024, 5:52 PM