Skip to content

Commit

Permalink
Expose internal errors from method channel to help debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Felipe C. C. Pinto <[email protected]>
  • Loading branch information
mateusfccp committed Sep 11, 2024
1 parent 32a77ac commit d46125c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
9 changes: 6 additions & 3 deletions update_available_android/lib/update_available_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
}
20 changes: 17 additions & 3 deletions update_available_platform_interface/lib/src/availability.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d46125c

Please sign in to comment.