JsonCacheInfoRepository: FormatException: Unexpected end of input (at character 1) ^
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start in json_cache_info_repository.dart at JsonCacheInfoRepository._readFile, around line 143, and inspect how an empty database JSON file reaches jsonDecode. Reproduce or cover the empty-file case, then verify initialization completes without a FormatException while preserving normal JSON loading.
Written by the indexing model from the issue text.
Description
🐛 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.<fn>(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<dynamic>;
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<dynamic>;
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:
- 📱 iOS
- 🤖 Android 13 (AP I33)
- Dominant language
- Dart
- Stars
- 810
- Forks
- 510
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Baseflow/flutter_cache_manager
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
Baseflow/flutter_cache_manager#507 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 30/100
Baseflow/flutter_cache_manager#501 · 1 comment · 3 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Baseflow/flutter_cache_manager#500 · 1 comment · 3 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
Baseflow/flutter_cache_manager#495 · 1 comment ·
All issues in Baseflow/flutter_cache_manager
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
code quality good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Suwayomi/Suwayomi-Tsumiru#479 ·
-
Build Failure: agora_rtc_engine compiled against android-31 while dependencies require android-34+ Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
conceptadev/noir#95 ·