-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[local_auth] Adopt structured errors, and remove useErrorDialogs
#9981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[local_auth] Adopt structured errors, and remove useErrorDialogs
#9981
Conversation
|
@tarrinneal Please review everything other than the Android and iOS changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request is a significant and well-executed refactoring of the local_auth plugin. It successfully replaces PlatformException with a more robust, structured LocalAuthException, and removes the useErrorDialogs option, giving developers more control over the user experience. The changes are consistently applied across all supported platforms, and the public API of the local_auth package is cleaner as a result. My review includes a few minor suggestions to improve the example applications to better demonstrate handling of the new exception type.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
tarrinneal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flagged a few typos, but the (non-ios, non-android) code all looks solid to me.
| print(e); | ||
| setState(() { | ||
| _isAuthenticating = false; | ||
| if (e.code != LocalAuthExceptionCode.userCanceled && | ||
| e.code != LocalAuthExceptionCode.systemCanceled) { | ||
| _authorized = | ||
| 'Error - ${e.code.name}${e.description != null ? ': ${e.description}' : ''}'; | ||
| } | ||
| }); | ||
| return; | ||
| } on PlatformException catch (e) { | ||
| print(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is having print statements in catch blocks normal for our examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not uncommon; our examples have historically been pretty bare-bones, and tend to skew more toward enabling manual testing than showing best practices. Some stick the errors into some in-app UI, which is an improvement, but also more code in the example.
It's something that ideally we should address, but polishing example apps that most clients will probably never actually run is also pretty low priority, so I've never followed up on it.
packages/local_auth/local_auth_platform_interface/lib/types/auth_exception.dart
Outdated
Show resolved
Hide resolved
packages/local_auth/local_auth_platform_interface/lib/types/auth_exception.dart
Outdated
Show resolved
Hide resolved
vashworth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS side LGTM
If I hadn't been interacting with the Android error codes there's no way I would have actually remembered to do it that way (per Flutter style). |
Platform interface portion of #9981 - Adds the new `LocalAuthException` class for structured errors. - Deprecates `AuthenticationOptions.useErrorDialogs` Part of: - flutter/flutter#113687 - flutter/flutter#175125 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
…tform implementations (#10147) Platform implementation portion of #9981 - Adds the new `LocalAuthException` class for structured errors. - Deprecates `AuthenticationOptions.useErrorDialogs` Part of: - flutter/flutter#113687 - flutter/flutter#175125 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
flutter/packages@835dccb...3747006 2025-10-16 [email protected] Manual roll Flutter from 7cd821c to a873a27 (22 revisions) (flutter/packages#10244) 2025-10-16 [email protected] [local_auth] Adopt structured errors, and remove `useErrorDialogs` (flutter/packages#9981) 2025-10-16 [email protected] [video_player] Move most Android event logic to Dart (flutter/packages#10128) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@835dccb...3747006 2025-10-16 [email protected] Manual roll Flutter from 7cd821c to a873a27 (22 revisions) (flutter/packages#10244) 2025-10-16 [email protected] [local_auth] Adopt structured errors, and remove `useErrorDialogs` (flutter/packages#9981) 2025-10-16 [email protected] [video_player] Move most Android event logic to Dart (flutter/packages#10128) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Switches from
PlatformExceptions to newLocalAuthExceptions, which contain structured error information (specifically, a code that is a documented enum, rather than a list of magic strings that are used inconsistently and not all documented), bringing the plugin into alignment with [our current best practices](https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#platform-exception-handling. In addition to being clearer and easier to use for clients, this adds significantly more granular error codes than we currently have, which allows clients to better handle specific cases.Since this must be done as a breaking change (since the current
PlatformExceptions are a combination of documented and de-facto API), this batches another breaking change, which is removing the error dialogs from the plugin, for the reasons described in flutter/flutter#175125.Since this is adding far more specific error codes, the PR also makes the internal change of passing essentially all native failure cases across the language boundary and then doing mapping to the cross-platform codes in Dart code, in keeping with our general recent practice of moving logic to the Dart side when there's no need for it to be native.
Fixes flutter/flutter#113687
Fixes flutter/flutter#175125
Fixes flutter/flutter#151513
Fixes flutter/flutter#132757
Fixes flutter/flutter#148947
Fixes flutter/flutter#173506
Fixes flutter/flutter#174191
Closes flutter/flutter#96646
Fixes flutter/flutter#117810
Closes flutter/flutter#141283
Closes flutter/flutter#173142
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3