Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit 022e6f4

Browse files
committed
refactor: improve headline reading history
- Propagate client exceptions - Handle client exceptions - Ensure history size limit
1 parent 45547ae commit 022e6f4

File tree

3 files changed

+1168
-589
lines changed

3 files changed

+1168
-589
lines changed

lib/ht_preferences_repository.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/// A Very Good Project created by Very Good CLI.
1+
/// Repository for managing user preferences, acting as an intermediary
2+
/// between BLoCs and the HtPreferencesClient.
23
library;
34

45
export 'src/ht_preferences_repository.dart';

lib/src/ht_preferences_repository.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// ignore_for_file: depend_on_referenced_packages, lines_longer_than_80_chars
1+
//
2+
// ignore_for_file: depend_on_referenced_packages, lines_longer_than_80_chars, cascade_invocations, avoid_catches_without_on_clauses
23

34
import 'dart:async';
45

@@ -298,8 +299,7 @@ class HtPreferencesRepository {
298299
try {
299300
return await _preferencesClient.getHeadlineReadingHistory();
300301
} on PreferenceNotFoundException {
301-
// If not found by client, return empty list as per repository logic
302-
return [];
302+
rethrow; // Propagate specific exceptions like other getters
303303
} on PreferenceUpdateException {
304304
rethrow;
305305
} catch (e, stackTrace) {
@@ -343,9 +343,7 @@ class HtPreferencesRepository {
343343
// Identify headlines to remove if limit is exceeded
344344
final headlinesToRemove = <Headline>[];
345345
if (updatedHistoryList.length > maxHistorySize) {
346-
headlinesToRemove.addAll(
347-
updatedHistoryList.sublist(maxHistorySize),
348-
);
346+
headlinesToRemove.addAll(updatedHistoryList.sublist(maxHistorySize));
349347
}
350348

351349
try {
@@ -355,12 +353,15 @@ class HtPreferencesRepository {
355353
// Remove oldest headlines via the client if necessary
356354
for (final oldHeadline in headlinesToRemove) {
357355
// Ignore errors during removal of old items, as adding the new one
358-
// is the primary goal. Log potentially?
356+
// is the primary goal.
359357
try {
360358
await _preferencesClient.removeHeadlineToHistory(oldHeadline.id);
361359
} catch (_) {
362-
// Log removal error? For now, we suppress it.
363-
// print('Warning: Failed to remove old history item ${oldHeadline.id}');
360+
// Intentionally suppress errors during the removal of *old* history
361+
// items. The primary goal is to add the *new* headline successfully.
362+
// Failing to prune an old item is less critical than failing the
363+
// entire add operation. Consider logging this error in a real app.
364+
// print('Warning: Failed to remove old history item ${oldHeadline.id}: $_');
364365
}
365366
}
366367
} on PreferenceUpdateException {

0 commit comments

Comments
 (0)