From 38efba0e6a1daddddaf9a0521723569c7fb4b493 Mon Sep 17 00:00:00 2001 From: 0xcf2f Date: Fri, 7 Feb 2025 22:47:56 +0100 Subject: [PATCH] feat(shorebird_code_push): override `toString` in exceptions (#266) Co-authored-by: Felix Angelov --- .../lib/src/shorebird_updater.dart | 8 ++++++ .../test/src/shorebird_updater_test.dart | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/shorebird_code_push/lib/src/shorebird_updater.dart b/shorebird_code_push/lib/src/shorebird_updater.dart index fa5dbf8..790bc85 100644 --- a/shorebird_code_push/lib/src/shorebird_updater.dart +++ b/shorebird_code_push/lib/src/shorebird_updater.dart @@ -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} @@ -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 diff --git a/shorebird_code_push/test/src/shorebird_updater_test.dart b/shorebird_code_push/test/src/shorebird_updater_test.dart index 4603acb..cd03965 100644 --- a/shorebird_code_push/test/src/shorebird_updater_test.dart +++ b/shorebird_code_push/test/src/shorebird_updater_test.dart @@ -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'), + ); + }); + }); }); }