| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library pub.command; | 5 library pub.command; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
| 11 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 12 import 'package:stack_trace/stack_trace.dart'; |
| 12 | 13 |
| 13 import 'command/cache.dart'; | 14 import 'command/cache.dart'; |
| 14 import 'command/deploy.dart'; | 15 import 'command/deploy.dart'; |
| 15 import 'command/help.dart'; | 16 import 'command/help.dart'; |
| 16 import 'command/install.dart'; | 17 import 'command/install.dart'; |
| 17 import 'command/lish.dart'; | 18 import 'command/lish.dart'; |
| 18 import 'command/list_package_dirs.dart'; | 19 import 'command/list_package_dirs.dart'; |
| 19 import 'command/serve.dart'; | 20 import 'command/serve.dart'; |
| 20 import 'command/update.dart'; | 21 import 'command/update.dart'; |
| 21 import 'command/uploader.dart'; | 22 import 'command/uploader.dart'; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 cache = new SystemCache.withSources(cacheDir, isOffline: isOffline); | 85 cache = new SystemCache.withSources(cacheDir, isOffline: isOffline); |
| 85 | 86 |
| 86 handleError(error) { | 87 handleError(error) { |
| 87 var trace = getAttachedStackTrace(error); | 88 var trace = getAttachedStackTrace(error); |
| 88 | 89 |
| 89 // This is basically the top-level exception handler so that we don't | 90 // This is basically the top-level exception handler so that we don't |
| 90 // spew a stack trace on our users. | 91 // spew a stack trace on our users. |
| 91 var message; | 92 var message; |
| 92 | 93 |
| 93 try { | 94 log.error(getErrorMessage(error)); |
| 94 // Most exception types have a "message" property. We prefer this since | |
| 95 // it skips the "Exception:", "HttpException:", etc. prefix that calling | |
| 96 // toString() adds. But, alas, "message" isn't actually defined in the | |
| 97 // base Exception type so there's no easy way to know if it's available | |
| 98 // short of a giant pile of type tests for each known exception type. | |
| 99 // | |
| 100 // So just try it. If it throws, default to toString(). | |
| 101 message = error.message; | |
| 102 } on NoSuchMethodError catch (_) { | |
| 103 message = error.toString(); | |
| 104 } | |
| 105 | |
| 106 log.error(message); | |
| 107 | 95 |
| 108 if (trace != null) { | 96 if (trace != null) { |
| 109 if (options['trace'] || !isUserFacingException(error)) { | 97 if (options['trace'] || !isUserFacingException(error)) { |
| 110 log.error(trace); | 98 log.error(new Trace.from(trace).terse); |
| 111 } else { | 99 } else { |
| 112 log.fine(trace); | 100 log.fine(new Trace.from(trace).terse); |
| 113 } | 101 } |
| 114 } | 102 } |
| 115 | 103 |
| 116 if (options['trace']) { | 104 if (options['trace']) { |
| 117 log.dumpTranscript(); | 105 log.dumpTranscript(); |
| 118 } else if (!isUserFacingException(error)) { | 106 } else if (!isUserFacingException(error)) { |
| 119 log.error(""" | 107 log.error(""" |
| 120 This is an unexpected error. Please run | 108 This is an unexpected error. Please run |
| 121 | 109 |
| 122 pub --trace ${new Options().arguments.map((arg) => "'$arg'").join(' ')} | 110 pub --trace ${new Options().arguments.map((arg) => "'$arg'").join(' ')} |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 }; | 195 }; |
| 208 | 196 |
| 209 for (var command in commands.values.toList()) { | 197 for (var command in commands.values.toList()) { |
| 210 for (var alias in command.aliases) { | 198 for (var alias in command.aliases) { |
| 211 commands[alias] = command; | 199 commands[alias] = command; |
| 212 } | 200 } |
| 213 } | 201 } |
| 214 | 202 |
| 215 return commands; | 203 return commands; |
| 216 } | 204 } |
| OLD | NEW |