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

Unified Diff: utils/pub/io.dart

Issue 11421159: Give all async exceptions in pub some sort of stack trace. (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
Index: utils/pub/io.dart
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index a85c7c3efbea2314ae1a20a4541c90f94953d5ba..0f2ae70f7792445d0b1944ed953f0f9392d40584 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -163,8 +163,16 @@ Future<File> createFileFromStream(InputStream stream, path) {
completer.complete(file);
};
+ // TODO(nweiz): remove this when issue 4061 is fixed.
+ var stackTrace;
+ try {
+ throw null;
+ } catch (_, localStackTrace) {
+ stackTrace = localStackTrace;
+ }
+
completeError(error) {
- if (!completer.isComplete) completer.completeException(error);
+ if (!completer.isComplete) completer.completeException(error, stackTrace);
}
stream.onError = completeError;
@@ -251,7 +259,15 @@ Future<List<String>> listDir(dir,
if (done) completer.complete(contents);
};
- lister.onError = (error) => completer.completeException(error);
+ // TODO(nweiz): remove this when issue 4061 is fixed.
+ var stackTrace;
+ try {
+ throw null;
+ } catch (_, localStackTrace) {
+ stackTrace = localStackTrace;
+ }
+
+ lister.onError = (error) => completer.completeException(error, stackTrace);
lister.onDir = (file) => contents.add(file);
lister.onFile = (file) {
if (!includeHiddenFiles && basename(file).startsWith('.')) return;
@@ -399,6 +415,14 @@ Future<String> readLine([StringInputStream stream]) {
stream.onError = null;
}
+ // TODO(nweiz): remove this when issue 4061 is fixed.
+ var stackTrace;
+ try {
+ throw null;
+ } catch (_, localStackTrace) {
+ stackTrace = localStackTrace;
+ }
+
var completer = new Completer();
stream.onClosed = () {
removeCallbacks();
@@ -412,7 +436,7 @@ Future<String> readLine([StringInputStream stream]) {
stream.onError = (e) {
removeCallbacks();
- completer.completeException(e);
+ completer.completeException(e, stackTrace);
};
return completer.future;
@@ -442,6 +466,14 @@ Future<InputStream> httpGet(uri) {
var client = new HttpClient();
var connection = client.getUrl(uri);
+ // TODO(nweiz): remove this when issue 4061 is fixed.
+ var stackTrace;
+ try {
+ throw null;
+ } catch (_, localStackTrace) {
+ stackTrace = localStackTrace;
+ }
+
connection.onError = (e) {
// Show a friendly error if the URL couldn't be resolved.
if (e is SocketIOException &&
@@ -454,14 +486,15 @@ Future<InputStream> httpGet(uri) {
}
client.shutdown();
- completer.completeException(e);
+ completer.completeException(e, stackTrace);
};
connection.onResponse = (response) {
if (response.statusCode >= 400) {
client.shutdown();
completer.completeException(
- new PubHttpException(response.statusCode, response.reasonPhrase));
+ new PubHttpException(response.statusCode, response.reasonPhrase),
+ stackTrace);
return;
}
@@ -504,11 +537,19 @@ Future pipeInputToInput(InputStream source, ListInputStream sink) {
Future<List<int>> consumeInputStream(InputStream stream) {
if (stream.closed) return new Future.immediate(<int>[]);
+ // TODO(nweiz): remove this when issue 4061 is fixed.
+ var stackTrace;
+ try {
+ throw null;
+ } catch (_, localStackTrace) {
+ stackTrace = localStackTrace;
+ }
+
var completer = new Completer<List<int>>();
var buffer = <int>[];
stream.onClosed = () => completer.complete(buffer);
stream.onData = () => buffer.addAll(stream.read());
- stream.onError = (e) => completer.completeException(e);
+ stream.onError = (e) => completer.completeException(e, stackTrace);
return completer.future;
}
@@ -516,11 +557,19 @@ Future<List<int>> consumeInputStream(InputStream stream) {
Future<String> consumeStringInputStream(StringInputStream stream) {
if (stream.closed) return new Future.immediate('');
+ // TODO(nweiz): remove this when issue 4061 is fixed.
+ var stackTrace;
+ try {
+ throw null;
+ } catch (_, localStackTrace) {
+ stackTrace = localStackTrace;
+ }
+
var completer = new Completer<String>();
var buffer = new StringBuffer();
stream.onClosed = () => completer.complete(buffer.toString());
stream.onData = () => buffer.add(stream.read());
- stream.onError = (e) => completer.completeException(e);
+ stream.onError = (e) => completer.completeException(e, stackTrace);
return completer.future;
}
@@ -591,8 +640,17 @@ Future _doProcess(Function fn, String executable, List<String> args, workingDir,
/// Due to issue 6984, it's necessary to drain the request body before closing
/// the response.
Future closeHttpResponse(HttpRequest request, HttpResponse response) {
+ // TODO(nweiz): remove this when issue 4061 is fixed.
+ var stackTrace;
+ try {
+ throw null;
+ } catch (_, localStackTrace) {
+ stackTrace = localStackTrace;
+ }
+
var completer = new Completer();
- request.inputStream.onError = completer.completeException;
+ request.inputStream.onError = (e) =>
+ completer.completeException(e, stackTrace);
request.inputStream.onData = request.inputStream.read;
request.inputStream.onClosed = () {
response.outputStream.close();
@@ -621,7 +679,7 @@ Future timeout(Future input, int milliseconds, String description) {
input.handleException((e) {
if (completer.future.isComplete) return false;
timer.cancel();
- completer.completeException(e);
+ completer.completeException(e, input.stackTrace);
return true;
});
input.then((value) {
@@ -728,7 +786,7 @@ Future<bool> extractTarGz(InputStream stream, destination) {
process.stderr.pipe(stderr, close: false);
});
processFuture.handleException((error) {
- completer.completeException(error);
+ completer.completeException(error, processFuture.stackTrace);
return true;
});

Powered by Google App Engine
This is Rietveld 408576698