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

Unified Diff: utils/pub/pub.dart

Issue 10421026: Make pub handle missing git more gracefully. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
Index: utils/pub/pub.dart
diff --git a/utils/pub/pub.dart b/utils/pub/pub.dart
index d2aea319014ab668ebe0ebb53a7a0bbe376330a1..3855d57c2b54a28f5af7f443426f6ff47905e04a 100644
--- a/utils/pub/pub.dart
+++ b/utils/pub/pub.dart
@@ -79,8 +79,8 @@ main() {
// Select the command.
var command = commands[args[0]];
if (command == null) {
- print('Unknown command "${args[0]}".');
- print('Run "pub help" to see available commands.');
+ printError('Unknown command "${args[0]}".');
+ printError('Run "pub help" to see available commands.');
exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits.
return;
}
@@ -139,11 +139,34 @@ class PubCommand {
// TODO(rnystrom): Will eventually need better logic to walk up
// subdirectories until we hit one that looks package-like. For now, just
// assume the cwd is it.
- Package.load(workingDir, cache.sources).then((package) {
+ var future = Package.load(workingDir, cache.sources).chain((package) {
nweiz 2012/05/23 00:46:26 No reason to assign this future to a var; you can
Bob Nystrom 2012/05/23 16:32:33 Done.
entrypoint = new Entrypoint(package, cache);
- onRun();
+ var commandFuture = onRun();
+ if (commandFuture == null) return new Future.immediate(true);
+
+ return commandFuture;
+ });
+
+ // This is basically the top-level exception handler so that we don't
+ // spew a stack trace on our users.
+ future.handleException((error) {
+ var message = error.toString();
nweiz 2012/05/23 00:46:26 We should probably have a --trace flag or somethin
Bob Nystrom 2012/05/23 16:32:33 Added TODO.
+
+ // TODO(rnystrom): The default exception implementation class puts
+ // "Exception:" in the output, so strip that off.
+ if (message.startsWith("Exception: ")) {
+ message = message.substring("Exception: ".length);
+ }
+
+ printError(message);
+ return true;
});
}
- abstract void onRun();
+ /**
+ * Override this to perform the specific command. Return a future that
+ * completes when the command is done or fails if the command fails. If the
+ * command is synchronous, it may return `null`.
nweiz 2012/05/23 00:46:26 What if a synchronous command has an error?
Bob Nystrom 2012/05/23 16:32:33 Good call. Added try block around onRun().
+ */
+ abstract Future onRun();
}

Powered by Google App Engine
This is Rietveld 408576698