diff --git a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart b/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart index f3293d26..2fe8e98b 100644 --- a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart +++ b/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart @@ -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)!; diff --git a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart b/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart index 03018d3f..724a778c 100644 --- a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart +++ b/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart @@ -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().having( + (e) => e.message, + 'message', + contains('error getting Flutter version'), + ), + ), + ); + }); }); }