diff --git a/flutter/lib/benchmark/state.dart b/flutter/lib/benchmark/state.dart index 5f38d8cb4..db9b07ecd 100644 --- a/flutter/lib/benchmark/state.dart +++ b/flutter/lib/benchmark/state.dart @@ -143,15 +143,21 @@ class BenchmarkState extends ChangeNotifier { modes: [taskRunner.perfMode, taskRunner.accuracyMode], benchmarks: benchmarks, ); - await resourceManager.handleResources( - resources, - needToPurgeCache, - downloadMissing, - ); - print('Finished loading resources with downloadMissing=$downloadMissing'); - error = null; - stackTrace = null; - taskConfigFailedToLoad = false; + try { + await resourceManager.handleResources( + resources, + needToPurgeCache, + downloadMissing, + ); + print('Finished loading resources with downloadMissing=$downloadMissing'); + error = null; + stackTrace = null; + taskConfigFailedToLoad = false; + } catch (e, s) { + print('Could not load resources due to error: $e'); + error = e; + stackTrace = s; + } await Wakelock.disable(); } diff --git a/flutter/lib/l10n/app_en.arb b/flutter/lib/l10n/app_en.arb index 49a94e174..fffb47b92 100644 --- a/flutter/lib/l10n/app_en.arb +++ b/flutter/lib/l10n/app_en.arb @@ -95,7 +95,6 @@ "dialogContentChecksumError": "The following files failed checksum validation:", "dialogContentNoSelectedBenchmarkError": "Please select at least one benchmark.", - "benchModePerformanceOnly": "Performance Only", "benchModeAccuracyOnly": "Accuracy Only", "benchModeSubmissionRun": "Submission Run", diff --git a/flutter/lib/resources/resource_manager.dart b/flutter/lib/resources/resource_manager.dart index 4d2459e8e..43b8b0da2 100644 --- a/flutter/lib/resources/resource_manager.dart +++ b/flutter/lib/resources/resource_manager.dart @@ -100,42 +100,47 @@ class ResourceManager { _loadingProgress = 0.001; _done = false; _onUpdate(); - - var internetResources = []; - for (final resource in resources) { - if (resource.path.startsWith(_dataPrefix)) continue; - if (isInternetResource(resource.path)) { - internetResources.add(resource); - continue; + try { + var internetResources = []; + for (final resource in resources) { + if (resource.path.startsWith(_dataPrefix)) continue; + if (isInternetResource(resource.path)) { + internetResources.add(resource); + continue; + } + throw 'forbidden path: ${resource.path} (only http://, https:// and local:// resources are allowed)'; } - throw 'forbidden path: ${resource.path} (only http://, https:// and local:// resources are allowed)'; - } - final internetPaths = internetResources.map((e) => e.path).toList(); - await cacheManager.cache( - internetPaths, - (double currentProgress, String currentPath) { - _loadingProgress = currentProgress; - _loadingPath = currentPath; - _onUpdate(); - }, - purgeOldCache, - downloadMissing, - ); - - final checksumFailed = await validateResourcesChecksum(resources); - if (checksumFailed.isNotEmpty) { - final mismatchedPaths = checksumFailed.map((e) => '\n${e.path}').join(); - throw 'Checksum validation failed for: $mismatchedPaths'; - } + final internetPaths = internetResources.map((e) => e.path).toList(); + try { + await cacheManager.cache( + internetPaths, + (double currentProgress, String currentPath) { + _loadingProgress = currentProgress; + _loadingPath = currentPath; + _onUpdate(); + }, + purgeOldCache, + downloadMissing, + ); + } on SocketException { + throw 'A network error has occurred. Please make sure you are connected to the internet.'; + } - // delete downloaded archives to free up disk space - await cacheManager.deleteArchives(internetPaths); + final checksumFailed = await validateResourcesChecksum(resources); + if (checksumFailed.isNotEmpty) { + final mismatchedPaths = checksumFailed.map((e) => '\n${e.path}').join(); + throw 'Checksum validation failed for: $mismatchedPaths'; + } - _loadingPath = ''; - _loadingProgress = 1.0; - _done = true; - _onUpdate(); + // delete downloaded archives to free up disk space + await cacheManager.deleteArchives(internetPaths); + } finally { + _loadingPath = ''; + _loadingProgress = 1.0; + _done = true; + _onUpdate(); + } } static Future getApplicationDirectory() async { diff --git a/flutter/lib/ui/settings/resources_screen.dart b/flutter/lib/ui/settings/resources_screen.dart index 9e154122e..fea8a5914 100644 --- a/flutter/lib/ui/settings/resources_screen.dart +++ b/flutter/lib/ui/settings/resources_screen.dart @@ -9,6 +9,7 @@ import 'package:mlperfbench/benchmark/state.dart'; import 'package:mlperfbench/localizations/app_localizations.dart'; import 'package:mlperfbench/store.dart'; import 'package:mlperfbench/ui/confirm_dialog.dart'; +import 'package:mlperfbench/ui/error_dialog.dart'; class ResourcesScreen extends StatefulWidget { const ResourcesScreen({super.key}); @@ -169,8 +170,15 @@ class _ResourcesScreen extends State { return AbsorbPointer( absorbing: downloading, child: ElevatedButton( - onPressed: () { - state.loadResources(downloadMissing: true); + onPressed: () async { + await state.loadResources(downloadMissing: true); + if (state.error != null) { + if (!mounted) return; + await showErrorDialog(context, [state.error.toString()]); + // Reset both the error and stacktrace for further operation + state.error = null; + state.stackTrace = null; + } }, style: ElevatedButton.styleFrom( backgroundColor: downloading ? Colors.grey : Colors.blue),