Skip to content

Conversation

@andrewkolos
Copy link
Contributor

@andrewkolos andrewkolos commented Mar 22, 2023

Fixes #123147.

Interestingly, arguing a non-integer value (asdf or 123.45) does not result in a ToolExit or crash. Instead, we default to null and a randomly-selected open port is used. However, this behavior seems consistent and intentional across different *port options across the tool, so I left it alone.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 22, 2023
@andrewkolos andrewkolos changed the title throw ToolExit when --web-port is an integer outside the valid TCP port range throw ToolExit when --web-port is an integer outside the valid TCP port range Mar 22, 2023
@andrewkolos andrewkolos marked this pull request as ready for review March 22, 2023 21:51
Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

The error messages now originate in ResidentWebRunner, which is conceptually isolated from the CLI. While this makes the error message slightly use useful for the --web-port case, this makes it less likely for the log messages to diverge from the actual port selection logic.
@andrewkolos
Copy link
Contributor Author

@christopherfujino re-requesting review because of minor changes in messages and test code

Received a non-integer value for port: ${debuggingOptions.port}
A randomly-chosen available port will be used instead.
''');
return globals.os.findFreePort();
Copy link
Contributor

Choose a reason for hiding this comment

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

nice


try {
return await asyncGuard(() async {
Future<int> getPort() async {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a local function, since it's only invoked once? Can we just inline this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't need to be a (local) function, but I don't think a function needs to be called more than once to justify its existence. In this case, I went with a function to

  • provide a clear start and end to port selection logic,
  • limit the scope of port selection logic, making it more clear that it doesn't interact with any other code within the asyncGuard callback, and
  • make it easier for first-time readers of the run method by moving the low-level details of port selection out of the way (you can fold/hide getPort and still understand what run does)

amongst other things.

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

Nit question about inlining getPort, but otherwise LGTM

@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2023
@auto-submit auto-submit bot merged commit 66e6acb into flutter:master Mar 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2023
@andrewkolos andrewkolos deleted the fix-invalid-tcp-port-crash branch April 21, 2023 19:53
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_tools] "ArgumentError: Invalid argument(s): Invalid port" when --web-port provided with invalid port

2 participants