Improve 'flutter downgrade' error message (#154434)
`flutter downgrade` fails if you haven't used `flutter upgrade`: ``` $ flutter downgrade There is no previously recorded version for channel "stable". ``` It's not clear what actions a user should take from this error message. Here's the new error message: ``` $ flutter downgrade It looks like you haven't run "flutter upgrade" on channel "stable". "flutter downgrade" undoes the last "flutter upgrade". To switch to a specific Flutter version, see: https://flutter.dev/to/switch-flutter-version ``` Depends on https://github.com/flutter/website/pull/11098
This commit is contained in:
parent
6abef22251
commit
3bda455f4e
@ -110,9 +110,18 @@ class DowngradeCommand extends FlutterCommand {
|
|||||||
final String? lastFlutterVersion = persistentToolState.lastActiveVersion(channel);
|
final String? lastFlutterVersion = persistentToolState.lastActiveVersion(channel);
|
||||||
final String? currentFlutterVersion = _flutterVersion?.frameworkRevision;
|
final String? currentFlutterVersion = _flutterVersion?.frameworkRevision;
|
||||||
if (lastFlutterVersion == null || currentFlutterVersion == lastFlutterVersion) {
|
if (lastFlutterVersion == null || currentFlutterVersion == lastFlutterVersion) {
|
||||||
final String trailing = await _createErrorMessage(workingDirectory, channel);
|
final String trailing = await _createErrorMessage(
|
||||||
|
workingDirectory,
|
||||||
|
channel,
|
||||||
|
);
|
||||||
throwToolExit(
|
throwToolExit(
|
||||||
'There is no previously recorded version for channel "$currentChannel".\n'
|
"It looks like you haven't run "
|
||||||
|
'"flutter upgrade" on channel "$currentChannel".\n'
|
||||||
|
'\n'
|
||||||
|
'"flutter downgrade" undoes the last "flutter upgrade".\n'
|
||||||
|
'\n'
|
||||||
|
'To switch to a specific Flutter version, see: '
|
||||||
|
'https://flutter.dev/to/switch-flutter-version'
|
||||||
'$trailing'
|
'$trailing'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -181,7 +190,10 @@ class DowngradeCommand extends FlutterCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Formats an error message that lists the currently stored versions.
|
// Formats an error message that lists the currently stored versions.
|
||||||
Future<String> _createErrorMessage(String workingDirectory, Channel currentChannel) async {
|
Future<String> _createErrorMessage(
|
||||||
|
String workingDirectory,
|
||||||
|
Channel currentChannel,
|
||||||
|
) async {
|
||||||
final StringBuffer buffer = StringBuffer();
|
final StringBuffer buffer = StringBuffer();
|
||||||
for (final Channel channel in Channel.values) {
|
for (final Channel channel in Channel.values) {
|
||||||
if (channel == currentChannel) {
|
if (channel == currentChannel) {
|
||||||
@ -191,11 +203,19 @@ class DowngradeCommand extends FlutterCommand {
|
|||||||
if (sha == null) {
|
if (sha == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final RunResult parseResult = await _processUtils!.run(<String>[
|
final RunResult parseResult = await _processUtils!.run(
|
||||||
'git', 'describe', '--tags', sha,
|
<String>['git', 'describe', '--tags', sha],
|
||||||
], workingDirectory: workingDirectory);
|
workingDirectory: workingDirectory,
|
||||||
|
);
|
||||||
if (parseResult.exitCode == 0) {
|
if (parseResult.exitCode == 0) {
|
||||||
buffer.writeln('Channel "${getNameForChannel(channel)}" was previously on: ${parseResult.stdout}.');
|
if (buffer.isEmpty) {
|
||||||
|
buffer.writeln();
|
||||||
|
}
|
||||||
|
buffer.writeln();
|
||||||
|
buffer.writeln(
|
||||||
|
'Channel "${getNameForChannel(channel)}" was previously on: '
|
||||||
|
'${parseResult.stdout}.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
|
@ -77,10 +77,16 @@ void main() {
|
|||||||
logger: bufferLogger,
|
logger: bufferLogger,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(createTestCommandRunner(command).run(const <String>['downgrade']),
|
expect(
|
||||||
throwsToolExit(message:
|
createTestCommandRunner(command).run(const <String>['downgrade']),
|
||||||
'There is no previously recorded version for channel "beta".\n'
|
throwsToolExit(message: '''
|
||||||
'Channel "master" was previously on: v1.2.3.'
|
It looks like you haven't run "flutter upgrade" on channel "beta".
|
||||||
|
|
||||||
|
"flutter downgrade" undoes the last "flutter upgrade".
|
||||||
|
|
||||||
|
To switch to a specific Flutter version, see: https://flutter.dev/to/switch-flutter-version
|
||||||
|
|
||||||
|
Channel "master" was previously on: v1.2.3.''',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user