Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#450 9 commenti 8 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
dart, flutter
Ambito
mobile

Direzione di ricerca

Inizia in json_cache_info_repository.dart, in corrispondenza di JsonCacheInfoRepository._readFile, intorno alla riga 143, e verifica come un file JSON del database vuoto arrivi a jsonDecode. Riproduci o copri il caso del file vuoto, quindi verifica che l'inizializzazione venga completata senza una FormatException, mantenendo il normale caricamento del JSON.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐛 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)
Lingua principale
Dart
Stelle
810
Fork
510
Merge medio
28m
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Baseflow/flutter_cache_manager

Tutte le issue di Baseflow/flutter_cache_manager

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.