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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 void runPub(String cacheDir, ArgResults options, List<String> arguments) { | 81 void runPub(String cacheDir, ArgResults options, List<String> arguments) { |
82 var captureStackChains = | 82 var captureStackChains = |
83 options['trace'] || | 83 options['trace'] || |
84 options['verbose'] || | 84 options['verbose'] || |
85 options['verbosity'] == 'all'; | 85 options['verbosity'] == 'all'; |
86 | 86 |
87 captureErrors(() => invokeCommand(cacheDir, options), | 87 captureErrors(() => invokeCommand(cacheDir, options), |
88 captureStackChains: captureStackChains).catchError((error, Chain chain) { | 88 captureStackChains: captureStackChains).catchError((error, Chain chain) { |
89 // This is basically the top-level exception handler so that we don't | 89 // This is basically the top-level exception handler so that we don't |
90 // spew a stack trace on our users. | 90 // spew a stack trace on our users. |
91 var message; | 91 var message = getErrorMessage(error); |
| 92 log.error(message); |
| 93 log.fine("Exception type: ${error.runtimeType}"); |
92 | 94 |
93 log.error(getErrorMessage(error)); | 95 if (log.json.enabled) { |
94 log.fine("Exception type: ${error.runtimeType}"); | 96 if (error is UsageException) { |
| 97 // Don't print usage info in JSON output. |
| 98 log.json.error(error.message); |
| 99 } else { |
| 100 log.json.error(error); |
| 101 } |
| 102 } |
95 | 103 |
96 if (options['trace'] || !isUserFacingException(error)) { | 104 if (options['trace'] || !isUserFacingException(error)) { |
97 log.error(chain.terse); | 105 log.error(chain.terse); |
98 } else { | 106 } else { |
99 log.fine(chain.terse); | 107 log.fine(chain.terse); |
100 } | 108 } |
101 | 109 |
102 if (error is ApplicationException && error.innerError != null) { | 110 if (error is ApplicationException && error.innerError != null) { |
103 var message = "Wrapped exception: ${error.innerError}"; | 111 var message = "Wrapped exception: ${error.innerError}"; |
104 if (error.innerTrace != null) message = "$message\n${error.innerTrace}"; | 112 if (error.innerTrace != null) message = "$message\n${error.innerTrace}"; |
(...skipping 19 matching lines...) Expand all Loading... |
124 return flushThenExit(exit_codes.SUCCESS); | 132 return flushThenExit(exit_codes.SUCCESS); |
125 }); | 133 }); |
126 } | 134 } |
127 | 135 |
128 /// Returns the appropriate exit code for [exception], falling back on 1 if no | 136 /// Returns the appropriate exit code for [exception], falling back on 1 if no |
129 /// appropriate exit code could be found. | 137 /// appropriate exit code could be found. |
130 int chooseExitCode(exception) { | 138 int chooseExitCode(exception) { |
131 if (exception is HttpException || exception is HttpException || | 139 if (exception is HttpException || exception is HttpException || |
132 exception is SocketException || exception is PubHttpException) { | 140 exception is SocketException || exception is PubHttpException) { |
133 return exit_codes.UNAVAILABLE; | 141 return exit_codes.UNAVAILABLE; |
134 } else if (exception is FormatException) { | 142 } else if (exception is FormatException || exception is DataException) { |
135 return exit_codes.DATA; | 143 return exit_codes.DATA; |
136 } else if (exception is UsageException) { | 144 } else if (exception is UsageException) { |
137 return exit_codes.USAGE; | 145 return exit_codes.USAGE; |
138 } else { | 146 } else { |
139 return 1; | 147 return 1; |
140 } | 148 } |
141 } | 149 } |
142 | 150 |
143 /// Walks the command tree and runs the selected pub command. | 151 /// Walks the command tree and runs the selected pub command. |
144 Future invokeCommand(String cacheDir, ArgResults mainOptions) { | 152 Future invokeCommand(String cacheDir, ArgResults mainOptions) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 if (Platform.operatingSystem != 'windows') return null; | 208 if (Platform.operatingSystem != 'windows') return null; |
201 | 209 |
202 return runProcess('ver', []).then((result) { | 210 return runProcess('ver', []).then((result) { |
203 if (result.stdout.join('\n').contains('XP')) { | 211 if (result.stdout.join('\n').contains('XP')) { |
204 log.error('Sorry, but pub is not supported on Windows XP.'); | 212 log.error('Sorry, but pub is not supported on Windows XP.'); |
205 return flushThenExit(exit_codes.USAGE); | 213 return flushThenExit(exit_codes.USAGE); |
206 } | 214 } |
207 }); | 215 }); |
208 }); | 216 }); |
209 } | 217 } |
OLD | NEW |