From d46125c3cd537c1a1f45d179e0669c170a56d365 Mon Sep 17 00:00:00 2001 From: "Mateus Felipe C. C. Pinto" Date: Wed, 11 Sep 2024 09:57:24 -0300 Subject: [PATCH] Expose internal errors from method channel to help debugging Signed-off-by: Mateus Felipe C. C. Pinto --- .../lib/update_available_android.dart | 9 ++++++--- .../lib/src/availability.dart | 20 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/update_available_android/lib/update_available_android.dart b/update_available_android/lib/update_available_android.dart index 1833d99..4666da5 100644 --- a/update_available_android/lib/update_available_android.dart +++ b/update_available_android/lib/update_available_android.dart @@ -18,10 +18,13 @@ final class UpdateAvailableAndroidPlugin extends UpdateAvailablePlatform { return switch (available) { true => const UpdateAvailable(), false => const NoUpdateAvailable(), - null => const UnknownAvailability(), + null => throw StateError("The implementation should return either 'true' or 'false'. This means that there's an issue with the implementation."), }; - } on PlatformException { - return const UnknownAvailability(); + } on PlatformException catch (error, stackTrace) { + return UnknownAvailability( + error: error, + stackTrace: stackTrace, + ); } } } diff --git a/update_available_platform_interface/lib/src/availability.dart b/update_available_platform_interface/lib/src/availability.dart index e24a2be..5dd363b 100644 --- a/update_available_platform_interface/lib/src/availability.dart +++ b/update_available_platform_interface/lib/src/availability.dart @@ -22,8 +22,22 @@ final class NoUpdateAvailable implements Availability { const NoUpdateAvailable(); } -/// Represents that it was not possible to determine if an update is available -/// or not. +/// Represents that it was not possible to determine if an update is available. final class UnknownAvailability implements Availability { - const UnknownAvailability(); + const UnknownAvailability({ + this.error, + this.stackTrace, + }); + + /// The error that made it impossible to determine the availability. + /// + /// It will only be non-null if a [PlatformException] is thrown form the + /// method channel. + final Object? error; + + /// The stack trace associated with [error]. + /// + /// It will only be non-null if a [PlatformException] is thrown form the + /// method channel. + final StackTrace? stackTrace; }