From 5db269c8269bde089ce7204e53ccc2e7065c5413 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 19 Mar 2020 23:44:50 +0100 Subject: [PATCH] NotesCache: Allow for json decoding errors The file may have gotten corrupted. --- lib/core/notes_cache.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/core/notes_cache.dart b/lib/core/notes_cache.dart index b317c8a4..04ed56b0 100644 --- a/lib/core/notes_cache.dart +++ b/lib/core/notes_cache.dart @@ -1,7 +1,9 @@ import 'dart:convert'; import 'dart:io'; +import 'package:fimber/fimber.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_crashlytics/flutter_crashlytics.dart'; import 'package:path/path.dart' as p; import 'package:collection/collection.dart'; @@ -104,7 +106,13 @@ class NotesCache { rethrow; } - return json.decode(contents).cast(); + try { + return json.decode(contents).cast(); + } catch (ex, st) { + Fimber.e("Exception - $ex for contents: $contents"); + await FlutterCrashlytics().logException(ex, st); + return []; + } } @visibleForTesting