fix(shorebird_cli): Print stderr output when flutter version check fails (#270)
This commit is contained in:
@@ -2,6 +2,13 @@ import 'package:shorebird_cli/src/shorebird_environment.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_process.dart';
|
||||
import 'package:shorebird_cli/src/validators/validators.dart';
|
||||
|
||||
class FlutterValidationException implements Exception {
|
||||
const FlutterValidationException(this.message);
|
||||
|
||||
/// The message associated with the exception.
|
||||
final String message;
|
||||
}
|
||||
|
||||
class ShorebirdFlutterValidator extends Validator {
|
||||
ShorebirdFlutterValidator({required this.runProcess});
|
||||
|
||||
@@ -120,11 +127,21 @@ This can cause unexpected behavior if the version gap is wide. If you're seeing
|
||||
['--version'],
|
||||
useVendedFlutter: !checkPathFlutter,
|
||||
);
|
||||
final output = result.stdout.toString();
|
||||
|
||||
if (result.exitCode != 0) {
|
||||
throw FlutterValidationException(
|
||||
'''
|
||||
Flutter version check did not complete successfully.
|
||||
${result.stderr}''',
|
||||
);
|
||||
}
|
||||
|
||||
final output = result.stdout.toString();
|
||||
final match = _flutterVersionRegex.firstMatch(output);
|
||||
if (match == null) {
|
||||
throw Exception('Could not find version match in $output');
|
||||
throw FlutterValidationException(
|
||||
'Could not find version match in $output',
|
||||
);
|
||||
}
|
||||
|
||||
return match.group(1)!;
|
||||
|
||||
@@ -103,8 +103,12 @@ Tools • Dart 2.19.6 • DevTools 2.20.1
|
||||
|
||||
when(() => pathFlutterVersionProcessResult.stdout)
|
||||
.thenReturn(pathFlutterVersionMessage);
|
||||
when(() => pathFlutterVersionProcessResult.stderr).thenReturn('');
|
||||
when(() => pathFlutterVersionProcessResult.exitCode).thenReturn(0);
|
||||
when(() => shorebirdFlutterVersionProcessResult.stdout)
|
||||
.thenReturn(shorebirdFlutterVersionMessage);
|
||||
when(() => shorebirdFlutterVersionProcessResult.stderr).thenReturn('');
|
||||
when(() => shorebirdFlutterVersionProcessResult.exitCode).thenReturn(0);
|
||||
when(() => gitBranchProcessResult.stdout).thenReturn(gitBranchMessage);
|
||||
when(() => gitStatusProcessResult.stdout).thenReturn(gitStatusMessage);
|
||||
});
|
||||
@@ -196,5 +200,22 @@ Tools • Dart 2.19.6 • DevTools 2.20.1
|
||||
|
||||
expect(() async => validator.validate(), throwsException);
|
||||
});
|
||||
|
||||
test('prints stderr output and throws if version check fails', () async {
|
||||
when(() => pathFlutterVersionProcessResult.exitCode).thenReturn(1);
|
||||
when(() => pathFlutterVersionProcessResult.stderr)
|
||||
.thenReturn('error getting Flutter version');
|
||||
|
||||
expect(
|
||||
() async => validator.validate(),
|
||||
throwsA(
|
||||
isA<FlutterValidationException>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
contains('error getting Flutter version'),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user