explicitly catch ArgumentError in exitsHappy(), and add tests#52757
explicitly catch ArgumentError in exitsHappy(), and add tests#52757christopherfujino merged 1 commit intoflutter:masterfrom
exitsHappy(), and add tests#52757Conversation
| } on Exception catch (error) { | ||
| _logger.printTrace('$cli failed with $error'); | ||
| return false; | ||
| } on ArgumentError catch (error) { |
There was a problem hiding this comment.
Why are we even calling it in this case?
There was a problem hiding this comment.
Sometimes we call exitsHappy to verify if the binary exists, e.g.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Not more reliable, but I think also not less reliable(?) The goal with processUtils was to have a small, concise API surface.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Oh, I see what you mean
There was a problem hiding this comment.
That would be changing what this function does slightly, however, by discarding the arguments.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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).
|
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 |
Description
After #52021,
exitsHappy()andexitsHappySync()only catchExceptions but notArgumentErrors, such as when the command being invoked doesn't exist. This PR explicitly catchesArgumentError.Related Issues
Fixes #52702
Tests
I added tests for both
exitsHappy()andexitsHappySync()that it catches bothExceptions andArgumentErrors.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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read [Handling breaking changes].