Baseflow / Baseflow/flutter_cached_network_image
Various Database Exceptions
- Dominant language
- Dart
- Stars
- 2.6k
- Forks
- 731
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 1
Description
## 🐛 Bug Report
We get different database exceptions from this module. Our expectation is that if there is such an exception, the module will bypass cache and fetch the image from the network. However, we do not see this happen. Instead, the onError is called back and the image is not loaded.
### Expected behavior
If cache read/write fails due to Database (or any other) error, please go to the network and fetch the image and return it.
### Reproduction steps
Use any of the 4 stack traces below to throw (hard code) an exception and see what happens.
Stacktrace 1
===========
DatabaseException(Error Domain=FMDatabase Code=11 "database disk image is malformed" UserInfo={NSLocalizedDescription=database disk image is malformed}) sql 'BEGIN EXCLUSIVE' args []
#0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:11)
#1 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:319)
#2 SqfliteDatabaseMixin.beginTransaction (package:sqflite_common/src/database_mixin.dart:457)
#3 SqfliteDatabaseMixin._runTransaction (package:sqflite_common/src/database_mixin.dart:482)
#4 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:319)
#5 SqfliteDatabaseMixin.doOpen (package:sqflite_common/src/database_mixin.dart:710)
#6 SqfliteDatabaseOpenHelper.openDatabase (package:sqflite_common/src/database.dart:44)
#7 SqfliteDatabaseFactoryMixin.openDatabase. (package:sqflite_common/src/factory_mixin.dart:110)
#8 ReentrantLock.synchronized. (package:synchronized/src/reentrant_lock.dart:37)
#9 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33)
#10 CacheObjectProvider.open (package:flutter_cache_manager/src/storage/cache_info_repositories/cache_object_provider.dart:30)
#11 CacheStore._getCacheDataFromDatabase (package:flutter_cache_manager/src/cache_store.dart:115)
Stacktrace 2
===========
DatabaseException(Error Domain=FMDatabase Code=14 "unable to open database file" UserInfo={NSLocalizedDescription=unable to open database file}) sql 'DELETE FROM cacheObject WHERE _id = ?' args [12903]
Stack trace:
#0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:11)
[asynchronous suspension>
#1 SqfliteDatabaseMixin.txnRawUpdate. (package:sqflite_common/src/database_mixin.dart:418)
#2 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33)
#3 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:344)
#4 CacheStore.retrieveCacheData. (package:flutter_cache_manager/src/cache_store.dart:79)
..., c6c6f4e0-545e-11ed-9561-5bd5ff64b794.jpg, "ab1e9a0fba3e472271c4a0c7f4273b96", 1667304955694, 1666700155759, 4576]
Stack trace:
#0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:11)
#1 SqfliteDatabaseMixin.txnRawInsert. (package:sqflite_common/src/database_mixin.dart:392)
#2 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33)
#3 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:344)
#4 CacheObjectProvider.insert (package:flutter_cache_manager/src/storage/cache_info_repositories/cache_object_provider.dart:101)
#5 CacheStore.putFile (package:flutter_cache_manager/src/cache_store.dart:59)
..., ..., 3ad518f0-2c85-11ed-8910-993ba0ac481b.jpg, "0502903e2942ace4006c1dda03854876", 1662923424767, 1662319053296, 6059, 7876, 7876]
Stack trace:
#0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:11)
#1 SqfliteDatabaseMixin.txnRawUpdate. (package:sqflite_common/src/database_mixin.dart:418)
#2 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33)
#3 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:344)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in lib/src/cache_store.dart and lib/src/storage/cache_info_repositories/cache_object_provider.dart, using the four supplied database stack traces to trace cache reads and writes. Verify how database failures are propagated, then confirm that a failed cache operation fetches from the network rather than invoking onError; done means the image is returned despite the simulated exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- databases, mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100