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

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: Respond to review. 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
« no previous file with comments | « utils/pub/io.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/pub.dart
diff --git a/utils/pub/pub.dart b/utils/pub/pub.dart
index d2aea319014ab668ebe0ebb53a7a0bbe376330a1..0832420885ebb3467add910c5c7fd686b9260635 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;
}
@@ -136,14 +136,44 @@ class PubCommand {
// TODO(rnystrom): Each command should define the arguments it expects and
// we can handle them generically here.
+ handleError(error) {
+ // This is basically the top-level exception handler so that we don't
+ // spew a stack trace on our users.
+ // TODO(rnystrom): Add --trace flag so stack traces can be enabled for
+ // debugging.
+ var message = error.toString();
+
+ // 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;
+ }
+
// 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) {
+ Package.load(workingDir, cache.sources).chain((package) {
entrypoint = new Entrypoint(package, cache);
- onRun();
- });
+
+ try {
+ var commandFuture = onRun();
+ if (commandFuture == null) return new Future.immediate(true);
+
+ return commandFuture;
+ } catch (var error) {
+ handleError(error);
+ }
+ }).handleException(handleError);
}
- 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`.
+ */
+ abstract Future onRun();
}
« no previous file with comments | « utils/pub/io.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698