Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Unify unhandled error reporting, add PlatformDispatcher.onError #32078
Unify unhandled error reporting, add PlatformDispatcher.onError #32078
Changes from 18 commits
f12f3b2
6edd564
f2c9356
fbae10c
608a26d
98f9d71
77a4bf9
8cf434f
1fd91cc
0e49a4a
d78d102
51fe9de
50984a9
5f713bc
d335d0f
96dbb17
ac742e2
92e0d62
6457bc8
12ebb87
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
The docstring doesn't seem placed in the right spot. It is referring to this as a method, but this is a typedef. This should be documented where it is used since the typedef itself is agnostic to how it is used.
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 documented in both places. Would you like me to remove it here?
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.
As a personal preference, I wouldn't introduce a typedef at all.
Dart has first class Function type syntax, and I (very personally) find typedefs confusing. I see the UpperCamelCase name and expect a class, not a function type.
Consider just removing the type. Who would suffer from that?
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.
I would if you don't take Irhn's suggestion. It can just reference the function that uses it instead of duplicating the documentation.
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.
Flutter's style is to prefer using typedefs - they benefit from having additional documentation and finding the right callsite, and being easier to read. I know this is a difference in what the Dart team prefers/linter suggests.
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.
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#naming-rules-for-typedefs-and-function-variables
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.
You should register the callback in the zone, using
Notice that that makes the stored function not necessarily be the same as the argument to the setter.
It might be a case where there shouldn't be a getter.
(Why is there a getter? What is the expected use?)
If you don't like having a setter without a getter, you can use the format used by
StreamSubscription
with.onData(callback)
instead of.onData = callback
.Consider not storing a zone if here is no callback. But better yet, use
bindBinaryCallback
instead to store the zone inside the callback instead of on the side: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.
This pattern is very commonly used in
hooks.dart
. I'd prefer to stick with it for this patch and have filed a bug flutter/flutter#101448 to track.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.
FWIW, generally speaking using Zones is pretty confusing and error prone. We try to steer our customers away from using them explicitly as much as possible.
Part of the motivation of this patch is to eliminate the need to use a custom zone to catch unhandled exceptions, and to avoid the usage of
addErrorListener
which can't catch certain types of errors when the code is invoked from C++.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.
Drop this branch.
You should call
_onErrorZone.runBinary
even if it's the same zone as where the function was registered. Some zones depend on getting to intercept the registered functions when they are called.Calling
Zone.run
doesn't necessarily just switch to the zone, it can do a lot of other things too in custom written zones.Always call
register
for callbacks, always callrun
to later run them.You can choose to do
bindBinaryCallback
instead ofregister
, then it remembers the zone for you and automatically runs the function in that zone when you call it. With theGuarded
, it also captures the error and reports it to that zone. That's definitely safer if you expose the registered function through a getter, so people can't accidentally forget to run it in the proper zone. (A registered function can validly throw if it's not run in the zone it was registered in.)Probably still want to remember the zone for the error handling below.
(Can't use
bindBinaryCallbackGuarded
because you need the return type.)The only zone where we sometimes skip calling
register
andrun
is the root zone, because we know it doesn't override any of theregister
orrun
functions.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.
Ditto on flutter/flutter#101448
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.
The
_onErrorZone
could have changed during the call above.Cache it in a local variable to ensure the error goes to the correct zone.
(Then add a test for changing the the zone during a callback, and make the callback throw.)
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.
Ditto on flutter/flutter#101448