From 851ff687884446c7c40106c355e6e69829188f9c Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 20 Jan 2021 15:17:58 -0800 Subject: [PATCH] [flutter_tools] throwToolExit from archive failure (#74259) --- packages/flutter_tools/lib/src/cache.dart | 8 ++++++-- .../test/general.shard/artifact_updater_test.dart | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 90a16a2149..5d1484ca60 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -1793,10 +1793,14 @@ class ArtifactUpdater { try { extractor(tempFile, location); - } on Exception { + } on Exception catch (err) { retries -= 1; if (retries == 0) { - rethrow; + throwToolExit( + 'Flutter could not download and/or extract $url. Ensure you have ' + 'network connectivity and all of the required dependencies listed at' + 'flutter.dev/setup.\nThe original exception was: $err.' + ); } _deleteIgnoringErrors(tempFile); continue; diff --git a/packages/flutter_tools/test/general.shard/artifact_updater_test.dart b/packages/flutter_tools/test/general.shard/artifact_updater_test.dart index 77ee314e65..46acae6830 100644 --- a/packages/flutter_tools/test/general.shard/artifact_updater_test.dart +++ b/packages/flutter_tools/test/general.shard/artifact_updater_test.dart @@ -5,6 +5,7 @@ import 'package:file/memory.dart'; import 'package:file/src/interface/file.dart'; import 'package:file_testing/file_testing.dart'; +import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/logger.dart'; @@ -246,7 +247,7 @@ void main() { expect(fileSystem.file('out/test'), isNot(exists)); }); - testWithoutContext('ArtifactUpdater will de-download a file if unzipping fails', () async { + testWithoutContext('ArtifactUpdater will re-download a file if unzipping fails', () async { final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final BufferLogger logger = BufferLogger.test(); @@ -294,7 +295,7 @@ void main() { expect(fileSystem.file('out/test'), exists); }); - testWithoutContext('ArtifactUpdater will bail if unzipping fails more than twice', () async { + testWithoutContext('ArtifactUpdater will bail with a tool exit if unzipping fails more than twice', () async { final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); final MemoryFileSystem fileSystem = MemoryFileSystem.test(); final BufferLogger logger = BufferLogger.test(); @@ -313,7 +314,7 @@ void main() { 'test message', Uri.parse('http:///test.zip'), fileSystem.currentDirectory.childDirectory('out'), - ), throwsA(isA())); + ), throwsA(isA())); expect(fileSystem.file('te,[/test'), isNot(exists)); expect(fileSystem.file('out/test'), isNot(exists)); }); @@ -337,7 +338,7 @@ void main() { 'test message', Uri.parse('http:///test.zip'), fileSystem.currentDirectory.childDirectory('out'), - ), throwsA(isA())); + ), throwsA(isA())); expect(fileSystem.file('te,[/test'), isNot(exists)); expect(fileSystem.file('out/test'), isNot(exists)); });