Baseflow / Baseflow/flutter_cache_manager

JsonCacheInfoRepository: FormatException: Unexpected end of input (at character 1) ^

未关闭 适合新手
#450 9 条评论 8 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Dart
星标
809
派生
510
平均合并
6 分钟
30 天内合并 PR
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。复现或覆盖空文件的情况,然后验证初始化能够在不产生 FormatException 的情况下完成,同时保留正常的 JSON 加载。

由索引模型根据 Issue 内容生成。

评估

技术栈
dart, flutter
领域
mobile
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
冷清
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。