fix(mobile): name the failing step in sign-in errors (#9263)

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 <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
This commit is contained in:
Tom Brow
2026-11-16 13:21:57 -08:00
committed by GitHub
parent aec5710453
commit d39545ebd4
4 changed files with 22 additions and 8 deletions

View File

@@ -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:

View File

@@ -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,

View File

@@ -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 = <StreamSubscription<Object>>[];
/// Advanced by every start or cancel, so an exchange from an abandoned

View File

@@ -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();