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:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
11 import 'package:source_maps/source_maps.dart'; | |
12 import 'package:stack_trace/stack_trace.dart'; | 11 import 'package:stack_trace/stack_trace.dart'; |
13 | 12 |
14 import '../lib/src/command.dart'; | 13 import '../lib/src/command.dart'; |
15 import '../lib/src/exceptions.dart'; | 14 import '../lib/src/exceptions.dart'; |
16 import '../lib/src/exit_codes.dart' as exit_codes; | 15 import '../lib/src/exit_codes.dart' as exit_codes; |
17 import '../lib/src/http.dart'; | 16 import '../lib/src/http.dart'; |
18 import '../lib/src/io.dart'; | 17 import '../lib/src/io.dart'; |
19 import '../lib/src/log.dart' as log; | 18 import '../lib/src/log.dart' as log; |
20 import '../lib/src/sdk.dart' as sdk; | 19 import '../lib/src/sdk.dart' as sdk; |
21 import '../lib/src/utils.dart'; | 20 import '../lib/src/utils.dart'; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 /// | 80 /// |
82 /// Handles and correctly reports any errors that occur while running. | 81 /// Handles and correctly reports any errors that occur while running. |
83 void runPub(String cacheDir, ArgResults options, List<String> arguments) { | 82 void runPub(String cacheDir, ArgResults options, List<String> arguments) { |
84 var captureStackChains = | 83 var captureStackChains = |
85 options['trace'] || | 84 options['trace'] || |
86 options['verbose'] || | 85 options['verbose'] || |
87 options['verbosity'] == 'all'; | 86 options['verbosity'] == 'all'; |
88 | 87 |
89 captureErrors(() => invokeCommand(cacheDir, options), | 88 captureErrors(() => invokeCommand(cacheDir, options), |
90 captureStackChains: captureStackChains).catchError((error, Chain chain) { | 89 captureStackChains: captureStackChains).catchError((error, Chain chain) { |
91 // This is basically the top-level exception handler so that we don't | 90 log.exception(error, chain); |
92 // spew a stack trace on our users. | |
93 if (error is SpanException) { | |
94 log.error(error.toString(useColors: canUseSpecialChars)); | |
95 } else { | |
96 log.error(getErrorMessage(error)); | |
97 } | |
98 log.fine("Exception type: ${error.runtimeType}"); | |
99 | |
100 if (log.json.enabled) { | |
101 if (error is UsageException) { | |
102 // Don't print usage info in JSON output. | |
103 log.json.error(error.message); | |
104 } else { | |
105 log.json.error(error); | |
106 } | |
107 } | |
108 | |
109 if (options['trace'] || !isUserFacingException(error)) { | |
110 log.error(chain.terse); | |
111 } else { | |
112 log.fine(chain.terse); | |
113 } | |
114 | |
115 if (error is WrappedException && error.innerError != null) { | |
116 var message = "Wrapped exception: ${error.innerError}"; | |
117 if (error.innerChain != null) message = "$message\n${error.innerChain}"; | |
118 log.fine(message); | |
119 } | |
120 | 91 |
121 if (options['trace']) { | 92 if (options['trace']) { |
122 log.dumpTranscript(); | 93 log.dumpTranscript(); |
123 } else if (!isUserFacingException(error)) { | 94 } else if (!isUserFacingException(error)) { |
124 log.error(""" | 95 log.error(""" |
125 This is an unexpected error. Please run | 96 This is an unexpected error. Please run |
126 | 97 |
127 pub --trace ${arguments.map((arg) => "'$arg'").join(' ')} | 98 pub --trace ${arguments.map((arg) => "'$arg'").join(' ')} |
128 | 99 |
129 and include the results in a bug report on http://dartbug.com/new. | 100 and include the results in a bug report on http://dartbug.com/new. |
130 """); | 101 """); |
131 } | 102 } |
132 | 103 |
133 return flushThenExit(chooseExitCode(error)); | 104 return flushThenExit(chooseExitCode(error)); |
134 }).then((_) { | 105 }).then((_) { |
135 // Explicitly exit on success to ensure that any dangling dart:io handles | 106 // Explicitly exit on success to ensure that any dangling dart:io handles |
136 // don't cause the process to never terminate. | 107 // don't cause the process to never terminate. |
137 return flushThenExit(exit_codes.SUCCESS); | 108 return flushThenExit(exit_codes.SUCCESS); |
138 }); | 109 }); |
139 } | 110 } |
140 | 111 |
141 /// Returns the appropriate exit code for [exception], falling back on 1 if no | 112 /// Returns the appropriate exit code for [exception], falling back on 1 if no |
142 /// appropriate exit code could be found. | 113 /// appropriate exit code could be found. |
143 int chooseExitCode(exception) { | 114 int chooseExitCode(exception) { |
| 115 while (exception is WrappedException) exception = exception.innerError; |
| 116 |
144 if (exception is HttpException || exception is http.ClientException || | 117 if (exception is HttpException || exception is http.ClientException || |
145 exception is SocketException || exception is PubHttpException) { | 118 exception is SocketException || exception is PubHttpException) { |
146 return exit_codes.UNAVAILABLE; | 119 return exit_codes.UNAVAILABLE; |
147 } else if (exception is FormatException || exception is DataException) { | 120 } else if (exception is FormatException || exception is DataException) { |
148 return exit_codes.DATA; | 121 return exit_codes.DATA; |
149 } else if (exception is UsageException) { | 122 } else if (exception is UsageException) { |
150 return exit_codes.USAGE; | 123 return exit_codes.USAGE; |
151 } else { | 124 } else { |
152 return 1; | 125 return 1; |
153 } | 126 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 if (Platform.operatingSystem != 'windows') return null; | 188 if (Platform.operatingSystem != 'windows') return null; |
216 | 189 |
217 return runProcess('ver', []).then((result) { | 190 return runProcess('ver', []).then((result) { |
218 if (result.stdout.join('\n').contains('XP')) { | 191 if (result.stdout.join('\n').contains('XP')) { |
219 log.error('Sorry, but pub is not supported on Windows XP.'); | 192 log.error('Sorry, but pub is not supported on Windows XP.'); |
220 return flushThenExit(exit_codes.USAGE); | 193 return flushThenExit(exit_codes.USAGE); |
221 } | 194 } |
222 }); | 195 }); |
223 }); | 196 }); |
224 } | 197 } |
OLD | NEW |