Skip to content

Commit

Permalink
Nicer error message for TLS errors (flutter#14285)
Browse files Browse the repository at this point in the history
Also some trivial improvements to style.
  • Loading branch information
Hixie authored Jan 26, 2018
1 parent 671c110 commit 014a225
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/flutter_tools/lib/src/base/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export 'dart:io'
// File NO! Use `file_system.dart`
// FileSystemEntity NO! Use `file_system.dart`
GZIP,
HandshakeException,
HttpClient,
HttpClientRequest,
HttpClientResponse,
Expand Down
13 changes: 12 additions & 1 deletion packages/flutter_tools/lib/src/base/net.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ Future<List<int>> _attempt(Uri url) async {
} else {
httpClient = new HttpClient();
}
final HttpClientRequest request = await httpClient.getUrl(url);
HttpClientRequest request;
try {
request = await httpClient.getUrl(url);
} on HandshakeException catch (error) {
printTrace(error.toString());
throwToolExit(
'Could not authenticate download server. You may be experiencing a man-in-the-middle attack,\n'
'your network may be compromised, or you may have malware installed on your computer.\n'
'URL: $url',
exitCode: kNetworkProblemExitCode,
);
}
final HttpClientResponse response = await request.close();
if (response.statusCode != 200) {
if (response.statusCode > 0 && response.statusCode < 500) {
Expand Down
18 changes: 12 additions & 6 deletions packages/flutter_tools/lib/src/doctor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ class _FlutterValidator extends DoctorValidator {
final FlutterVersion version = FlutterVersion.instance;

messages.add(new ValidationMessage('Flutter version ${version.frameworkVersion} at ${Cache.flutterRoot}'));
if (Cache.flutterRoot.contains(' '))
if (Cache.flutterRoot.contains(' ')) {
messages.add(new ValidationMessage.error(
'Flutter SDK install paths with spaces are not yet supported. (https://github.com/flutter/flutter/issues/6577)\n'
'Please move the SDK to a path that does not include spaces.'));
'Flutter SDK install paths with spaces are not yet supported. '
'(https://github.com/flutter/flutter/issues/6577)\n'
'Please move the SDK to a path that does not include spaces.'
));
}
messages.add(new ValidationMessage(
'Framework revision ${version.frameworkRevisionShort} '
'(${version.frameworkAge}), ${version.frameworkDate}'
Expand All @@ -215,13 +218,16 @@ class _FlutterValidator extends DoctorValidator {

// Check that the binaries we downloaded for this platform actually run on it.
if (!_genSnapshotRuns(genSnapshotPath)) {
messages.add(new ValidationMessage.error('Downloaded executables cannot execute '
'on host (see https://github.com/flutter/flutter/issues/6207 for more information)'));
messages.add(new ValidationMessage.error(
'Downloaded executables cannot execute '
'on host (see https://github.com/flutter/flutter/issues/6207 for more information)'
));
valid = ValidationType.partial;
}

return new ValidationResult(valid, messages,
statusInfo: 'on ${os.name}, locale ${platform.localeName}, channel ${version.channel}');
statusInfo: 'on ${os.name}, locale ${platform.localeName}, channel ${version.channel}'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Future<String> getServiceFromUrl(String url, String rootDir, String serviceName)
if (url.startsWith('android-sdk:') && androidSdk != null) {
// It's something shipped in the standard android SDK.
return url.replaceAll('android-sdk:', '${androidSdk.directory}/');
} else if (url.startsWith('http')) {
} else if (url.startsWith('http:') || url.startsWith('https:')) {
// It's a regular file to download.
return await cache.getThirdPartyFile(url, serviceName);
} else {
Expand Down

0 comments on commit 014a225

Please sign in to comment.