Fixed
Status Update
Comments
cl...@google.com <cl...@google.com>
cl...@google.com <cl...@google.com> #2
I see that you were expecting to catch the exception as part of collecting on the Pager Flow<PagingData>
.
We don't want to propagate errors that way and cannot even if we wanted to. PagingData
is a wrapper around an internal Flow<PagingEvent
which is collected internally.
Paging exposes errors by PagingSource
returning a lazyPagingItems.loadState
(in compose's case). For example in your case, the LoadState would be:
refresh=Error(endOfPaginationReached=false, error=android.database.sqlite.SQLiteException: malformed MATCH expression: [a* OR ] (code 1 SQLITE_ERROR)
LimitOffsetPagingSource
currently does not return LoadResult.Error but it makes sense to add that.
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit e12e6ff2dd9421be11d2af72e603ad279bb0dfb7
Author: Clara Fok <clarafok@google.com>
Date: Mon Oct 16 17:35:42 2023
LimitOffsetPagingSource to return LoadResult.Error
Currently any Exception resulting from calling LimitOffsetPagingSource.load isn't caught, resulting in app crashes unless users caught it as part of the db query. Now we return LoadResult.Error instead which is propagated as a LoadStateUpdate. This also makes it easier to recover from errors.
Test: ./gradlew room:room-paging:cC
Bug: 302708983
Relnote: "Exceptions thrown from PagingSource loads will now be propagated as a LoadStateUpdate of LoadResult.Error containing the Throwable. This error state is observable through PagingDataAdapter.loadStateFlow(Views) or LazyPagingItems.loadState(Compose). Note that this marks a behavioral change where in the past load errors will bubble up as an Exception thrown by the dao method that triggered the load."
Change-Id: I93887de62a4fc76d1abe4ade60ed524a41d9d4e8
M room/room-paging/src/androidTest/kotlin/androidx/room/paging/LimitOffsetPagingSourceTest.kt
M room/room-paging/src/main/java/androidx/room/paging/LimitOffsetPagingSource.kt
https://android-review.googlesource.com/2792152
Branch: androidx-main
commit e12e6ff2dd9421be11d2af72e603ad279bb0dfb7
Author: Clara Fok <clarafok@google.com>
Date: Mon Oct 16 17:35:42 2023
LimitOffsetPagingSource to return LoadResult.Error
Currently any Exception resulting from calling LimitOffsetPagingSource.load isn't caught, resulting in app crashes unless users caught it as part of the db query. Now we return LoadResult.Error instead which is propagated as a LoadStateUpdate. This also makes it easier to recover from errors.
Test: ./gradlew room:room-paging:cC
Bug: 302708983
Relnote: "Exceptions thrown from PagingSource loads will now be propagated as a LoadStateUpdate of LoadResult.Error containing the Throwable. This error state is observable through PagingDataAdapter.loadStateFlow(Views) or LazyPagingItems.loadState(Compose). Note that this marks a behavioral change where in the past load errors will bubble up as an Exception thrown by the dao method that triggered the load."
Change-Id: I93887de62a4fc76d1abe4ade60ed524a41d9d4e8
M room/room-paging/src/androidTest/kotlin/androidx/room/paging/LimitOffsetPagingSourceTest.kt
M room/room-paging/src/main/java/androidx/room/paging/LimitOffsetPagingSource.kt
jo...@gmail.com <jo...@gmail.com> #5
Thank you for the reply and the fix.
pr...@google.com <pr...@google.com> #6
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.room:room-paging:2.6.1
Description
Technical Details
This sample app showcases how there is no error propagation available when using default PagingSource in queries. The sample app has a text field that filters a list of animals. The MATCH statement is used to throw an Exception but there may be other ways to do this as well.
Steps to reproduce:
Under the covers, the default implementation of PagingSource in DAO queries is LimitOffsetPagingSource.
In this particular case, we have options to mitigate this:
In lieu of an actual fix, there should probably be documentation that acknowledges and warns about situations using the default PagingSource, particularly in instances where the MATCH statement is used with user input since this is a common use case with FTS4 entities that requires special care.
There are a few StackOverflow issues that mention this issue, both reported years ago, but I could not find any bug reports: