From d39545ebd4d97023cb991125693e57f534225a0d Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Mon, 16 Nov 2026 13:21:57 -0800 Subject: [PATCH] fix(mobile): name the failing step in sign-in errors (#9263) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Organization sign-in shows the same "Couldn't sign in. Try again." (landing page) or "Sign in failed. Try again." (in-app banner) for every failure after the browser hands control back: a rejected or stale callback, a keychain write that doesn't stick, a code exchange the server refuses, a session for a different account, or a malformed response. Server logs can't tell these apart either, because the exchange can succeed on the server and still fail on the device. So a user's screenshot of the error tells us nothing about which step broke. This appends a short code naming the failure, for example "Couldn't sign in (account-storage). Try again." or "Sign in failed (browser-restartLogin). Try again." The code is the failure's enum name, prefixed by where it came from (`browser-` for the callback, `account-` for the exchange and session). An unexpected failure type throws instead of showing a made-up code. ### Validation - Focused test changes: the sign-in banner's recovery test now checks the code in the message for two account failures and one browser failure, at each text scale. - Full mobile suite (`flutter test`) and `flutter analyze` pass. - Not yet: an automated app run reproducing a failed sign-in to capture the new message on screen. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Tom Brow Co-authored-by: Tom Brow Co-authored-by: studio --- .../features/onboarding/organization_sign_in_banner.dart | 7 ++++--- mobile/lib/organization_app_entry.dart | 5 ++++- mobile/lib/shared/hosted/organization_sign_in.dart | 9 +++++++++ .../onboarding/organization_sign_in_banner_test.dart | 9 +++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/mobile/lib/features/onboarding/organization_sign_in_banner.dart b/mobile/lib/features/onboarding/organization_sign_in_banner.dart index 409bfa5920..d06241c0d7 100644 --- a/mobile/lib/features/onboarding/organization_sign_in_banner.dart +++ b/mobile/lib/features/onboarding/organization_sign_in_banner.dart @@ -41,9 +41,10 @@ class OrganizationSignInBanner extends HookConsumerWidget { actionLabel = 'Cancel'; onAction = () => unawaited(signIn.cancel()); case OrganizationSessionStatus.signedOut: - message = signIn.failure == null - ? "It looks like you're signed out." - : 'Sign in failed. Try again.'; + message = switch (signIn.failureCode) { + null => "It looks like you're signed out.", + final code => 'Sign in failed ($code). Try again.', + }; actionLabel = 'Sign in'; onAction = () => unawaited(signIn.signIn()); case OrganizationSessionStatus.signedIn: diff --git a/mobile/lib/organization_app_entry.dart b/mobile/lib/organization_app_entry.dart index 0fd28af40b..006b08116e 100644 --- a/mobile/lib/organization_app_entry.dart +++ b/mobile/lib/organization_app_entry.dart @@ -139,7 +139,10 @@ class OrganizationAppEntry extends HookConsumerWidget { 'Sign in on a device that has it, then try again.', null => null, } ?? - (signIn.failure != null ? 'Couldn’t sign in. Try again.' : null); + switch (signIn.failureCode) { + null => null, + final code => 'Couldn’t sign in ($code). Try again.', + }; return PairingPage( connectionLanding: true, diff --git a/mobile/lib/shared/hosted/organization_sign_in.dart b/mobile/lib/shared/hosted/organization_sign_in.dart index 0a9f3353d2..169211e9fa 100644 --- a/mobile/lib/shared/hosted/organization_sign_in.dart +++ b/mobile/lib/shared/hosted/organization_sign_in.dart @@ -49,6 +49,15 @@ class OrganizationSignIn extends ChangeNotifier { /// The last sign-in or session-check failure, cleared by the next attempt. Object? failure; + /// [failure] as a short code shown with the failure message, so a reported + /// screenshot names the step that failed. + String? get failureCode => switch (failure) { + null => null, + final BrowserAuthFailure f => 'browser-${f.name}', + final AccountFailure f => 'account-${f.name}', + final f => throw StateError('Unexpected sign-in failure: $f'), + }; + final _subscriptions = >[]; /// Advanced by every start or cancel, so an exchange from an abandoned diff --git a/mobile/test/features/onboarding/organization_sign_in_banner_test.dart b/mobile/test/features/onboarding/organization_sign_in_banner_test.dart index c9cabb9a44..bbfe064985 100644 --- a/mobile/test/features/onboarding/organization_sign_in_banner_test.dart +++ b/mobile/test/features/onboarding/organization_sign_in_banner_test.dart @@ -176,16 +176,17 @@ void main() { expect(find.byType(ReconnectCapsule), findsNothing); }, ); - for (final failure in [ - AccountFailure.storage, - AccountFailure.unavailable, + for (final (failure, code) in [ + (AccountFailure.storage, 'account-storage'), + (AccountFailure.unavailable, 'account-unavailable'), + (BrowserAuthFailure.restartLogin, 'browser-restartLogin'), ]) { testWidgets('$failure keeps sign-in recovery available at $scale', ( tester, ) async { signIn.failure = failure; await mount(tester, scale: scale); - expect(find.text('Sign in failed. Try again.'), findsOneWidget); + expect(find.text('Sign in failed ($code). Try again.'), findsOneWidget); expectVisibleCard(tester); await tester.tap(find.text('Sign in')); await tester.pumpAndSettle();