Skip to content

Commit

Permalink
feat: ignore outdated ratings cache (#1882)
Browse files Browse the repository at this point in the history
Old cache data for the ratings will be missing the snap_name field. If
that's the case we should ignore the error and throw away the cache
data.

UDENG-5771
  • Loading branch information
d-loose authored Jan 14, 2025
2 parents c040de7 + 58e0865 commit 055cf32
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/app_center/lib/snapd/cache_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:snapd/snapd.dart';
import 'package:ubuntu_logger/ubuntu_logger.dart';
import 'package:xdg_directories/xdg_directories.dart' as xdg;

@visibleForTesting
final cachePath =
'${xdg.cacheHome.path}/${p.basename(Platform.resolvedExecutable)}/snapd';

final _log = Logger('cache_file');

class CacheFile {
CacheFile(
String path, {
Expand Down Expand Up @@ -109,7 +112,14 @@ class CacheFile {

Future<RatingsData?> readRatingsData() async {
final data = await read() as Map?;
return data != null ? RatingsData.fromJson(data.cast()) : null;
if (data == null) return null;

try {
return RatingsData.fromJson(data.cast());
} on Error catch (e) {
_log.debug('Caught error while reading ratings cache data: $e');
return null;
}
}

void writeRatingsDataSync(RatingsData ratingsData) {
Expand Down

0 comments on commit 055cf32

Please sign in to comment.