| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// The main entrypoint for the pub command line application. | 5 /// The main entrypoint for the pub command line application. |
| 6 library pub; | 6 library pub; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import '../../pkg/args/lib/args.dart'; | 9 import '../../pkg/args/lib/args.dart'; |
| 10 import '../../pkg/path/lib/path.dart' as path; | 10 import '../../pkg/path/lib/path.dart' as path; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 commandOptions = commandParser.parse(commandArgs); | 228 commandOptions = commandParser.parse(commandArgs); |
| 229 } on FormatException catch (e) { | 229 } on FormatException catch (e) { |
| 230 log.error(e.message); | 230 log.error(e.message); |
| 231 log.error('Use "pub help" for more information.'); | 231 log.error('Use "pub help" for more information.'); |
| 232 exit(exit_codes.USAGE); | 232 exit(exit_codes.USAGE); |
| 233 } | 233 } |
| 234 | 234 |
| 235 handleError(error, trace) { | 235 handleError(error, trace) { |
| 236 // This is basically the top-level exception handler so that we don't | 236 // This is basically the top-level exception handler so that we don't |
| 237 // spew a stack trace on our users. | 237 // spew a stack trace on our users. |
| 238 var message = error.toString(); | 238 var message; |
| 239 | 239 |
| 240 // TODO(rnystrom): The default exception implementation class puts | 240 try { |
| 241 // "Exception:" in the output, so strip that off. | 241 // Most exception types have a "message" property. We prefer this since |
| 242 if (message.startsWith("Exception: ")) { | 242 // it skips the "Exception:", "HttpException:", etc. prefix that calling |
| 243 message = message.substring("Exception: ".length); | 243 // toString() adds. But, alas, "message" isn't actually defined in the |
| 244 // base Exception type so there's no easy way to know if it's available |
| 245 // short of a giant pile of type tests for each known exception type. |
| 246 // |
| 247 // So just try it. If it throws, default to toString(). |
| 248 message = error.message; |
| 249 } on NoSuchMethodError catch (_) { |
| 250 message = error.toString(); |
| 244 } | 251 } |
| 245 | 252 |
| 246 log.error(message); | 253 log.error(message); |
| 247 if (globalOptions['trace'] && trace != null) { | 254 if (globalOptions['trace'] && trace != null) { |
| 248 log.error(trace); | 255 log.error(trace); |
| 249 log.dumpTranscript(); | 256 log.dumpTranscript(); |
| 250 } | 257 } |
| 251 | 258 |
| 252 exit(_chooseExitCode(error)); | 259 exit(_chooseExitCode(error)); |
| 253 } | 260 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (exception is HttpException || exception is HttpParserException || | 316 if (exception is HttpException || exception is HttpParserException || |
| 310 exception is SocketIOException || exception is PubHttpException) { | 317 exception is SocketIOException || exception is PubHttpException) { |
| 311 return exit_codes.UNAVAILABLE; | 318 return exit_codes.UNAVAILABLE; |
| 312 } else if (exception is FormatException) { | 319 } else if (exception is FormatException) { |
| 313 return exit_codes.DATA; | 320 return exit_codes.DATA; |
| 314 } else { | 321 } else { |
| 315 return 1; | 322 return 1; |
| 316 } | 323 } |
| 317 } | 324 } |
| 318 } | 325 } |
| OLD | NEW |