Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Unified Diff: packages/package_config/lib/discovery.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/package_config/codereview.settings ('k') | packages/package_config/lib/discovery_analysis.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/package_config/lib/discovery.dart
diff --git a/packages/package_config/lib/discovery.dart b/packages/package_config/lib/discovery.dart
index 8e42af79d78fe213b9ec5d1f4ae9d034e99eb0d0..4c09eecfbabcde5ca56b1a1e086bbb7f4dbdc1dc 100644
--- a/packages/package_config/lib/discovery.dart
+++ b/packages/package_config/lib/discovery.dart
@@ -28,22 +28,21 @@ import "src/packages_io_impl.dart";
/// resolution file, for example one specified using a `--packages`
/// command-line parameter.
Future<Packages> loadPackagesFile(Uri packagesFile,
- {Future<List<int>> loader(Uri uri)}) {
+ {Future<List<int>> loader(Uri uri)}) async {
Packages parseBytes(List<int> bytes) {
Map<String, Uri> packageMap = pkgfile.parse(bytes, packagesFile);
return new MapPackages(packageMap);
}
if (packagesFile.scheme == "file") {
File file = new File.fromUri(packagesFile);
- return file.readAsBytes().then(parseBytes);
+ return parseBytes(await file.readAsBytes());
}
if (loader == null) {
- return _httpGet(packagesFile).then(parseBytes);
+ return parseBytes(await _httpGet(packagesFile));
}
- return loader(packagesFile).then(parseBytes);
+ return parseBytes(await loader(packagesFile));
}
-
/// Create a [Packages] object for a package directory.
///
/// The [packagesDir] URI should refer to a directory.
@@ -63,7 +62,6 @@ Packages getPackagesDirectory(Uri packagesDir) {
return new NonFilePackagesDirectoryPackages(packagesDir);
}
-
/// Discover the package configuration for a Dart script.
///
/// The [baseUri] points to either the Dart script or its directory.
@@ -93,7 +91,7 @@ Packages getPackagesDirectory(Uri packagesDir) {
/// The content should be a UTF-8 encoded `.packages` file, and must return an
/// error future if loading fails for any reason.
Future<Packages> findPackages(Uri baseUri,
- {Future<List<int>> loader(Uri unsupportedUri)}) {
+ {Future<List<int>> loader(Uri unsupportedUri)}) {
if (baseUri.scheme == "file") {
return new Future<Packages>.sync(() => findPackagesFromFile(baseUri));
} else if (loader != null) {
@@ -191,17 +189,19 @@ Packages findPackagesFromFile(Uri fileBaseUri) {
/// of the requested `.packages` file as bytes, which will be assumed to be
/// UTF-8 encoded.
Future<Packages> findPackagesFromNonFile(Uri nonFileUri,
- {Future<List<int>> loader(Uri name)}) {
+ {Future<List<int>> loader(Uri name)}) async {
if (loader == null) loader = _httpGet;
Uri packagesFileUri = nonFileUri.resolve(".packages");
- return loader(packagesFileUri).then((List<int> fileBytes) {
+
+ try {
+ List<int> fileBytes = await loader(packagesFileUri);
Map<String, Uri> map = pkgfile.parse(fileBytes, packagesFileUri);
return new MapPackages(map);
- }, onError: (_) {
+ } catch (_) {
// Didn't manage to load ".packages". Assume a "packages/" directory.
Uri packagesDirectoryUri = nonFileUri.resolve("packages/");
return new NonFilePackagesDirectoryPackages(packagesDirectoryUri);
- });
+ }
}
/// Fetches a file over http.
« no previous file with comments | « packages/package_config/codereview.settings ('k') | packages/package_config/lib/discovery_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698