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. |
* |