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

Unified Diff: utils/pub/hosted_source.dart

Issue 11369066: Show better error messages in network failures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « no previous file | utils/pub/io.dart » ('j') | utils/pub/package.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/hosted_source.dart
diff --git a/utils/pub/hosted_source.dart b/utils/pub/hosted_source.dart
index eb4b86fd79013c09f817ab113253d19c9189b532..36c295d7a7c77b7b1c826c5346b58ef237307a6e 100644
--- a/utils/pub/hosted_source.dart
+++ b/utils/pub/hosted_source.dart
@@ -41,12 +41,7 @@ class HostedSource extends Source {
var doc = JSON.parse(body);
return doc['versions'].map((version) => new Version.parse(version));
}).transformException((ex) {
- if (ex is PubHttpException && ex.statusCode == 404) {
- throw 'Could not find package "${parsed.first}" on ${parsed.last}.';
- }
-
- // Otherwise re-throw the original exception.
- throw ex;
+ _throwFriendlyError(ex, parsed.first, parsed.last);
});
}
@@ -58,8 +53,11 @@ class HostedSource extends Source {
var parsed = _parseDescription(id.description);
var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/"
"${id.version}.yaml";
+
return httpGetString(fullUrl).transform((yaml) {
return new Pubspec.parse(yaml, systemCache.sources);
+ }).transformException((ex) {
+ _throwFriendlyError(ex, id, parsed.last);
});
}
@@ -121,6 +119,27 @@ class HostedSource extends Source {
_parseDescription(description);
}
+ /// When an error occurs trying to read something about [package] from [url],
+ /// this tries to translate into a more user friendly error message. Always
+ /// throws an error, either the original one or a better one.
+ void _throwFriendlyError(ex, package, url) {
+ if (ex is PubHttpException && ex.statusCode == 404) {
+ throw 'Could not find package "${package}" at ${url}.';
nweiz 2012/11/05 19:55:36 Why "${package}" and "${url}" over "$package" and
Bob Nystrom 2012/11/05 20:43:06 Done. There used to be more complex expressions in
+ }
+
+ if (ex is TimeoutException) {
+ throw 'Timed out trying to find package "${package}" at ${url}.';
+ }
+
+ if (ex is io.SocketIOException) {
+ throw 'Got socket error trying to find package "${package}" at ${url}.\n'
+ '${ex.osError}';
+ }
+
+ // Otherwise re-throw the original exception.
+ throw ex;
+ }
+
/**
* Parses the description for a package.
*
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/package.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698