Skip to content

Commit

Permalink
feat(shorebird_code_push): override toString in exceptions (#266)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Angelov <felix@shorebird.dev>
  • Loading branch information
Abdulrasheed1729 and felangel authored Feb 7, 2025
1 parent 78c84e5 commit 38efba0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions shorebird_code_push/lib/src/shorebird_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ReadPatchException implements Exception {

/// The human-readable error message.
final String message;

@override
String toString() => '[ShorebirdUpdater] ReadPatchException: $message';
}

/// {@template update_exception}
Expand All @@ -41,6 +44,11 @@ class UpdateException implements Exception {

/// The reason the update failed.
final UpdateFailureReason reason;

@override
String toString() {
return '[ShorebirdUpdater] UpdateException: $message (${reason.name})';
}
}

/// Log message when the Shorebird updater is unavailable in the current
Expand Down
25 changes: 25 additions & 0 deletions shorebird_code_push/test/src/shorebird_updater_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,30 @@ void main() {
expect(ShorebirdUpdater.new, returnsNormally);
}),
);

group(UpdateException, () {
test('overrides toString', () {
const message = 'message';
const reason = UpdateFailureReason.downloadFailed;
const exception = UpdateException(message: message, reason: reason);
expect(
exception.toString(),
equals(
'[ShorebirdUpdater] UpdateException: $message (${reason.name})',
),
);
});
});

group(ReadPatchException, () {
test('overrides toString', () {
const message = 'message';
const exception = ReadPatchException(message: message);
expect(
exception.toString(),
equals('[ShorebirdUpdater] ReadPatchException: $message'),
);
});
});
});
}

0 comments on commit 38efba0

Please sign in to comment.