Baseflow / Baseflow/flutter_cache_manager
JsonCacheInfoRepository: FormatException: Unexpected end of input (at character 1) ^
- 主要言語
- Dart
- スター
- 809
- フォーク
- 510
- 平均マージ
- 6分
- マージ済み PR(30日)
- 1
説明
## 🐛 Bug Report
occasionally this error is generated when initializing CacheManager with JsonCacheInfoRepository
```
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: FormatException: Unexpected end of input (at character 1)
^
at .jsonDecode(dart:convert)
at JsonCacheInfoRepository._readFile(json_cache_info_repository.dart:143)
at JsonCacheInfoRepository.open(json_cache_info_repository.dart:40)
at new CacheStore.(cache_store.dart:34)
```
This happens when the {databaseName}.json file is created but empty and jsonString = ""
```
JsonCacheInfoRepository.dart: _readFile()
final json = jsonDecode(jsonString) as List;
```
A possible solution would be to check that the file is not empty before decoding the json
```
if (await file.exists() && await file.length() > 0) {
try {
final jsonString = await file.readAsString();
final json = jsonDecode(jsonString) as List;
```
> note: I don't know why the json file is empty and not with an empty list []
### Expected behavior
no error
### Configuration
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.16.1, on Microsoft Windows [Versi¢n 10.0.22631.3296], locale es-CL)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.8.2)
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.87.2)
[√] Connected device (4 available)
[√] Network resources
• No issues found!
**Version:** 3.3.1
**Platform:**
- [ ] :iphone: iOS
- [x] :robot: Android 13 (AP I33)
コントリビューションガイド
調査の方向性
json_cache_info_repository.dart の JsonCacheInfoRepository._readFile(143 行目付近)から始め、空のデータベース JSON ファイルがどのように jsonDecode に渡されるかを調べてください。空ファイルのケースを再現するかカバーし、その後、通常の JSON の読み込みを維持したまま、FormatException なしで初期化が完了することを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- dart, flutter
- 領域
- mobile
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 68/100