From c44674bc6a2d79d02406b3a8e674f7caaa74119d Mon Sep 17 00:00:00 2001 From: Edson Amaya Date: Tue, 23 Jul 2024 14:42:49 -0600 Subject: [PATCH] Clean serialized file if exist a format error --- packages/core/lib/state.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/lib/state.dart b/packages/core/lib/state.dart index 48632ba..8c376f7 100644 --- a/packages/core/lib/state.dart +++ b/packages/core/lib/state.dart @@ -201,9 +201,16 @@ abstract class PersistedState implements AsyncStateNotifier { return; }).catchError((e) { _error = e; - final wrappedError = ErrorLoadingStorage(e); - errorHandler(wrappedError); - throw wrappedError; + // Clean file if exist a format error + if(_error.toString().contains("FormatException")) { + _store.setPersisted(_key, {}); + log("Clean file $_key with format error", + kind: LogFilterKind.warning); + } else { + final wrappedError = ErrorLoadingStorage(e); + errorHandler(wrappedError); + throw wrappedError; + } }); }