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

Unified Diff: sdk/lib/_internal/pub/lib/src/io.dart

Issue 315063002: Display timeout errors more gracefully. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 6 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 | « sdk/lib/_internal/pub/lib/src/http.dart ('k') | sdk/lib/_internal/pub/lib/src/progress.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/io.dart
diff --git a/sdk/lib/_internal/pub/lib/src/io.dart b/sdk/lib/_internal/pub/lib/src/io.dart
index d02335049e1a97d741af77fcd9985a90ae138b3b..6e119735a0b55f2e6b48199d49f36c0d8e88cce5 100644
--- a/sdk/lib/_internal/pub/lib/src/io.dart
+++ b/sdk/lib/_internal/pub/lib/src/io.dart
@@ -630,22 +630,34 @@ Future _doProcess(Function fn, String executable, List<String> args,
environment: environment));
}
-/// Wraps [input] to provide a timeout. If [input] completes before
-/// [milliseconds] have passed, then the return value completes in the same way.
-/// However, if [milliseconds] pass before [input] has completed, it completes
-/// with a [TimeoutException] with [description] (which should be a fragment
-/// describing the action that timed out).
+/// Wraps [input], an asynchronous network operation to provide a timeout.
+///
+/// If [input] completes before [milliseconds] have passed, then the return
+/// value completes in the same way. However, if [milliseconds] pass before
+/// [input] has completed, it completes with a [TimeoutException] with
+/// [description] (which should be a fragment describing the action that timed
+/// out).
+///
+/// [url] is the URL being accessed asynchronously.
///
/// Note that timing out will not cancel the asynchronous operation behind
/// [input].
-Future timeout(Future input, int milliseconds, String description) {
+Future timeout(Future input, int milliseconds, Uri url, String description) {
// TODO(nwiez): Replace this with [Future.timeout].
var completer = new Completer();
var duration = new Duration(milliseconds: milliseconds);
var timer = new Timer(duration, () {
- completer.completeError(new TimeoutException(
- 'Timed out while $description.', duration),
- new Chain.current());
+ // Include the duration ourselves in the message instead of passing it to
+ // TimeoutException since we show nicer output.
+ var message = 'Timed out after ${niceDuration(duration)} while '
+ '$description.';
+
+ if (url.host == "pub.dartlang.org" ||
+ url.host == "storage.googleapis.com") {
+ message += "\nThis is likely a transient error. Please try again later.";
+ }
+
+ completer.completeError(new TimeoutException(message), new Chain.current());
});
input.then((value) {
if (completer.isCompleted) return;
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/http.dart ('k') | sdk/lib/_internal/pub/lib/src/progress.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698