Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves error reporting in the Firebase Messaging Android plugin by formatting nested exception causes (such as FCM registration failures) to include the underlying error details. It also adds comprehensive unit tests for this formatting logic and an integration test that simulates network blockages. The review feedback suggests wrapping a shell command execution inside a finally block in MainActivity.kt with a try-catch to prevent masking any original exceptions.
| } finally { | ||
| executeShell("cmd connectivity set-chain3-enabled false") | ||
| } |
There was a problem hiding this comment.
In the finally block, if executeShell throws an exception, it will mask and discard any original exception thrown in the preceding try block. To prevent masking the original exception, wrap the finally block's shell execution in a try-catch block.
| } finally { | |
| executeShell("cmd connectivity set-chain3-enabled false") | |
| } | |
| } finally { | |
| try { | |
| executeShell("cmd connectivity set-chain3-enabled false") | |
| } catch (_: Exception) {} | |
| } |
Description
Since
firebase-messaging25.1.0 (firebase/firebase-android-sdk#8087),FirebaseMessaging.blockingRegister()wraps registration failures innew IOException("FCM Registration failed!", e)instead ofnew IOException(e). The underlying failure (such asSERVICE_NOT_AVAILABLE,TIMEOUT, orAUTHENTICATION_FAILED) is preserved onThrowable.getCause(), rather than in the outergetMessage().FlutterFirebaseMessagingPluginpreviously forwarded onlyexception.getMessage()across the AndroidMethodChanneland dropped the cause chain, so Dart callers ofgetToken()andregister()received the identical[firebase_messaging/unknown] java.io.IOException: FCM Registration failed!message regardless of the underlying reason.This change adds
FlutterFirebaseMessagingPlugin.formatExceptionMessage(...)and uses it in bothresult.error(...)andgetExceptionDetails(...). It walksThrowable.getCause()(guarded against cycles), skips plainTasks.awaitExecutionExceptionwrappers whose message only mirrors their cause, and appends each distinct underlying cause asCaused by: <cause>when not already present in the message.Related Issues
Fixes #18997
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
Test plan
FlutterFirebaseMessagingPluginExceptionTestcoveringFCM Registration failed!wrapped inExecutionException, multi-hop cause chains, customExecutionExceptionmessages, pre-25.1.0 non-duplication, single/plain exceptions, null messages/exceptions, and cyclic cause chains; ran./gradlew :firebase_messaging:testDebugUnitTest.packages/firebase_messaging/firebase_messaging/example/integration_test/e2e_test.dartthat unregisters, blockscom.google.android.gmsnetworking viacmd connectivity, callsregister(), and verifies the thrownFirebaseException.messagematchesFCM Registration failed! Caused by: \S+before restoring networking; ranflutter test integration_test/e2e_test.dart --dart-define=CI=trueon an Android emulator (20 passed, 0 failed).flutter_plugin_tools format,./.github/workflows/scripts/validate-formatting.sh,melos run check-license-header, andflutter_plugin_tools analyze --base-branch=origin/main --custom-analysis=.github/workflows/config/custom_analysis.yaml.