Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flutter_tools] Add timeout duration to error and handle exceptions for HttpHostValidator. #98290

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

Merged

Conversation

royarg02
Copy link
Contributor

@royarg02 royarg02 commented Feb 11, 2022

Includes the timeout duration, handles exceptions for invalid FLUTTER_DOCTOR_HOST_TIMEOUT, PUB_HOSTED_URL or FLUTTER_STORAGE_BASE_URL environment variables of HttpHostValidator.

Also includes some code hand-formatting/cleanup for readability.

Adds tests to make sure the timeout is being displayed and exceptions are handled accordingly.

Fixes #98286.
Fixes #98328.

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 Feb 11, 2022

final List<_HostValidationResult> availabilityResults =
(await Future.wait(availabilityResultFutures)).toList();
final List<_HostValidationResult> availabilityResults = await Future.wait(_requiredHosts.map(_checkHostAvailability));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why the .toList was needed here

Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you condense lines 89-92 into one? I feel like it is more difficult to read as a one-liner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So should I reintroduce availabilityResultFutures?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it was just a style refactor, I would prefer having availabilityResultFutures

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that .toList() was redundant

@royarg02 royarg02 marked this pull request as draft February 12, 2022 06:14
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@royarg02 royarg02 force-pushed the doctor_host_validator_timeout branch from 69f00bb to fbf784e Compare February 13, 2022 06:31
return _HostValidationResult.success(host);
} on TimeoutException {
return _HostValidationResult.fail(
host, 'Failed to connect to $host in seconds');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already mention $host before this message, no need to mention it again.

} on HttpException catch (e) {
return _HostValidationResult.fail(host,
'An error occurred while checking the HTTP host: ${e.toString()}');
return _HostValidationResult.fail(host, 'An error occurred while checking the HTTP host: ${e.message}');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

e.toString() => e.message

@royarg02 royarg02 marked this pull request as ready for review February 13, 2022 07:32
expect(result.type, equals(ValidationType.notAvailable));
}
});

testWithoutContext('one http hosts are not available', () async {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Duplicate test

Copy link
Contributor

Choose a reason for hiding this comment

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

yikes, good catch

}
});

testWithoutContext('one http hosts are not available', () async {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Duplicate test

@royarg02 royarg02 force-pushed the doctor_host_validator_timeout branch 2 times, most recently from 1140d90 to 3e6c6fb Compare February 18, 2022 07:27
try {
final int timeout =
int.parse(_platform.environment[kDoctorHostTimeout] ?? '10');
timeout = int.parse(_platform.environment[kDoctorHostTimeout] ?? '10');
Copy link
Contributor

Choose a reason for hiding this comment

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

can this also be lifted outside of the try block?

Copy link
Contributor Author

@royarg02 royarg02 Feb 25, 2022

Choose a reason for hiding this comment

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

I can't, see #98328.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you catching FormatException?

Copy link
Contributor Author

@royarg02 royarg02 Feb 26, 2022

Choose a reason for hiding this comment

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

Not in this PR, but in the (future)PR that fixes that issue, and I see no point in moving this line when eventually it has to be moved back.

Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to catch and toolexit on formatexception in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing specific, thought it would be better to land separate PRs to fix separate issues, but I can include all in one if you are okay with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me as long as it's not a lot more code, which I imagine it wouldn't be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@christopherfujino I've pushed a commit that handles all possible exceptions, PTAL.

@royarg02 royarg02 force-pushed the doctor_host_validator_timeout branch from 3e6c6fb to 2aa5a65 Compare February 26, 2022 05:02
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

@royarg02 royarg02 changed the title [flutter_tools] Include timeout duration in HttpHostValidator error [flutter_tools] Add timeout duration to error and handle exceptions for HttpHostValidator. Feb 28, 2022
@royarg02 royarg02 force-pushed the doctor_host_validator_timeout branch 2 times, most recently from a4061bd to cbde691 Compare March 1, 2022 06:47
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • Please get at least one approved review if you are already a member or two member reviews if you are not a member before re-applying this label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@christopherfujino
Copy link
Contributor

@Jasguerrero can you give another review on this one?

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2022
@royarg02 royarg02 deleted the doctor_host_validator_timeout branch March 13, 2022 07:05
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
4 participants