Refactor flutter command exit code - part 2 (#6817)
* convert pubGet to throw ToolExit on non-zero exit code * convert commandValidator to throw ToolExit for non-zero exit code * convert flutter commands to throw ToolExit for non-zero exit code * use convenience method throwToolExit * only show "if this problem persists" for unusual exceptions
This commit is contained in:
@@ -27,8 +27,8 @@ String _homeDirPath;
|
||||
/// where the tool should exit with a clear message to the user
|
||||
/// and no stack trace unless the --verbose option is specified.
|
||||
/// For example: network errors
|
||||
void throwToolExit(String message, { int exitCode }) {
|
||||
throw new ToolExit(message, exitCode: exitCode);
|
||||
void throwToolExit(String message, { int exitCode, bool isUnusual: false }) {
|
||||
throw new ToolExit(message, exitCode: exitCode, isUnusual: isUnusual);
|
||||
}
|
||||
|
||||
/// Specialized exception for expected situations
|
||||
@@ -36,10 +36,12 @@ void throwToolExit(String message, { int exitCode }) {
|
||||
/// and no stack trace unless the --verbose option is specified.
|
||||
/// For example: network errors
|
||||
class ToolExit implements Exception {
|
||||
ToolExit(this.message, { this.exitCode });
|
||||
|
||||
ToolExit(this.message, { this.exitCode, this.isUnusual: false });
|
||||
|
||||
final String message;
|
||||
final int exitCode;
|
||||
final bool isUnusual;
|
||||
|
||||
@override
|
||||
String toString() => "Exception: $message";
|
||||
|
||||
@@ -24,6 +24,7 @@ Future<List<int>> fetchUrl(Uri url) async {
|
||||
'Download failed: $url\n'
|
||||
' because (${response.statusCode}) ${response.reasonPhrase}',
|
||||
exitCode: kNetworkProblemExitCode,
|
||||
isUnusual: true,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ Future<List<int>> fetchUrl(Uri url) async {
|
||||
throw new ToolExit(
|
||||
'Download failed: $url\n $e',
|
||||
exitCode: kNetworkProblemExitCode,
|
||||
isUnusual: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user