Skip to content

Commit

Permalink
fix(shorebird_cli): Print stderr output when flutter version check fa…
Browse files Browse the repository at this point in the history
…ils (#270)
  • Loading branch information
bryanoltman authored Apr 7, 2023
1 parent 0ff20e6 commit 2dc180b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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});

Expand Down Expand Up @@ -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)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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'),
),
),
);
});
});
}

0 comments on commit 2dc180b

Please sign in to comment.