Skip to content

Commit

Permalink
Merge pull request #93 from North-Two-Five/fix/issues_74_80
Browse files Browse the repository at this point in the history
Clean serialized JSON file if exist a format error
  • Loading branch information
MichaelGHSeg authored Aug 1, 2024
2 parents e45c723 + ef41f4b commit e9c9cc3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/core/lib/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,16 @@ abstract class PersistedState<T> implements AsyncStateNotifier<T> {
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;
}
});
}

Expand Down

0 comments on commit e9c9cc3

Please sign in to comment.