Skip to content

explicitly catch ArgumentError in exitsHappy(), and add tests#52757

Merged
christopherfujino merged 1 commit intoflutter:masterfrom
chris-forks:fix-exits-happy-sync
Mar 17, 2020
Merged

explicitly catch ArgumentError in exitsHappy(), and add tests#52757
christopherfujino merged 1 commit intoflutter:masterfrom
chris-forks:fix-exits-happy-sync

Conversation

@christopherfujino
Copy link
Copy Markdown
Contributor

Description

After #52021, exitsHappy() and exitsHappySync() only catch Exceptions but not ArgumentErrors, such as when the command being invoked doesn't exist. This PR explicitly catches ArgumentError.

Related Issues

Fixes #52702

Tests

I added tests for both exitsHappy() and exitsHappySync() that it catches both Exceptions and ArgumentErrors.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read [Handling breaking changes].

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@christopherfujino christopherfujino added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 17, 2020
Copy link
Copy Markdown
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.

thanks!

@christopherfujino christopherfujino merged commit 071d4eb into flutter:master Mar 17, 2020
@christopherfujino christopherfujino deleted the fix-exits-happy-sync branch March 17, 2020 19:56
} on Exception catch (error) {
_logger.printTrace('$cli failed with $error');
return false;
} on ArgumentError catch (error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we even calling it in this case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sometimes we call exitsHappy to verify if the binary exists, e.g.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahhh ok, I see now, and we're catching ArgumentError from _processManager. Is this more reliable than just calling https://api.flutter.dev/flutter/package-process_process/ProcessManager/canRun.html?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not more reliable, but I think also not less reliable(?) The goal with processUtils was to have a small, concise API surface.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, I mean we could call that in here first and return false if it's false, rather than trying to catch an argument exception. That way if some other code starts throwing that we don't end up swallowing the unrelated exception.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i.e. on line 541 of this file (or maybe line 539), if (!_processManager.canRun(cli.first), environment: environment)) { return false; } - probably also with either asserts or guards against cli being null or empty.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see what you mean

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would be changing what this function does slightly, however, by discarding the arguments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DeviceManager.canListAnything should probably check discoverer.supportsPlatform before querying discoverer.canListAnything. The similar code in EmulatorManager in emulator.dart probably needs a similar fix. (Sorry for not suggesting this earlier, but the fix in this PR was needed as well.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RE discarding arguments - after checking canRun, you can still use the existing logic, but avoid trying to catch an argument error.

My concern with catching argument error is that it can be thrown for a number of reasons, including errors in the upstream code (e.g. someone accidentally makes the string null, or passes in an empty array).

@christopherfujino christopherfujino mentioned this pull request Mar 20, 2020
13 tasks
@lock
Copy link
Copy Markdown

lock Bot commented Apr 2, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock Bot locked and limited conversation to collaborators Apr 2, 2020
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.

Crash in 'flutter create' (?)

4 participants