Skip to content

Conversation

@lrhn
Copy link
Contributor

@lrhn lrhn commented Mar 20, 2020

Description

Inserts 5 counts of // ignore: deprecated_member_use.

The runZoned method deprecates the onError parameter.
Invocations using that parameter must use runZonedGuarded instead.

This prepares Flutter for the deprecation. The same places need to be migrated to using
runZonedGuarded when the SDK change has been ported to Flutter.
Then the deprecated member will be removed in a follow-up CL when the most important
packages have been migrated.

This change is needed to enable landing the initial Dart SDK change, which must happen before the migration can begin. See: https://dart-review.googlesource.com/c/sdk/+/137302/24

Related Issues

dart-lang/sdk#40681

The `runZoned` method deprecates the `onError` parameter.
Invocations using that parameter must use `runZonedGuarded` instead.

This prepares Flutter for the deprecation. The same places need to be migrated to using
`runZonedGuarded` when the SDK change has been ported to Flutter.
Then the deprecated member will be removed in a follow-up CL when the most important
packages have been migrated.
@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 20, 2020
@vsmenon vsmenon requested a review from zanderso March 23, 2020 15:22
Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'guarded' suffix on Zone calls implies that the error handling is slightly different afaiu. Is that the case here, or is the only difference that runZoneGuarded accepts onError and can return null?

@lrhn
Copy link
Contributor Author

lrhn commented Mar 23, 2020

The difference is that in runZonedGuarded:

  • onError is a required parameter,
  • has type void Function(Object, StackTrace) (no unary functions accepted),
  • and the return type is always nullable in Null Safe mode, where runZoned is potentially not.

(And that the onError parameter of runZoned is going away).

@zanderso
Copy link
Member

So, sorry if I'm misunderstanding the docs, but for example, there is a difference in the behavior of Zone.run and Zone.runGuarded. If I'm reading things correctly, Zone.runGuarded catches synchronous exceptions and sends them to the Zone's handler, whereas Zone.run does not send synchronous exceptions to the Zone's handler. I was wondering if there was any similar distinction between runZoned and runZonedGuarded. That is, does runZonedGuarded send synchronous exceptions to the error handling callback rather than propagating them?

@lrhn
Copy link
Contributor Author

lrhn commented Mar 24, 2020

Yes, runZonedGuarded does (or will, when landed) send synchronous exceptions to the onError handler, and then return null instead. That's why it needs a nullable return type, where runZoned does not, and for Null Safety, we want to split the two use cases out so they won't both get the nullable return type.

I have updated the breaking-change issue, which was showing the first proposed change, not the bigger-but-long-term-better change that we ended up with.

@lrhn
Copy link
Contributor Author

lrhn commented Mar 24, 2020

(I can't commit to the Flutter repository, so someone with commit rights need to press the button).

@vsmenon vsmenon merged commit af5194d into flutter:master Mar 24, 2020
@zanderso
Copy link
Member

I filed #53185 to track switching over.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants