-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[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
base: main
Are you sure you want to change the base?
[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>
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
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
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.
Interesting that Gemini didn't catch those typos, it's caught similar mistakes in other PRs.
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
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.
LGTM from the Android side.
Aside, my brain does not like 'canceled' with one 'l' no matter how many times Google tells me that's how we do it here in America.
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). |
Switches from
PlatformException
s to newLocalAuthException
s, 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
PlatformException
s 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.yaml
with 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.md
to 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