countCrash method

  1. @override
int countCrash(
  1. String release
)
override

Counts one more crash on this device for release and returns the count. Persisted with the records, because a crash loop is a sequence of restarts, and a limit that restarts with them limits nothing.

Implementation

@override
int countCrash(String release) {
  Map<String, Object?> counts = <String, Object?>{};
  try {
    final Object? json = jsonDecode(storage.read(_counts) ?? '{}');
    if (json is Map<String, Object?>) counts = json;
  } on FormatException {
    // Cut short: the count restarts rather than refusing this crash.
  }
  final Object? previous = counts[release];
  final int next = (previous is int ? previous : 0) + 1;
  counts[release] = next;
  storage.write(_counts, jsonEncode(counts));
  return next;
}