fix(shorebird_cli): warn instead of error when no flavor provided to app that has flavors (#3352)

This commit is contained in:
Bryan Oltman
2025-10-14 16:09:28 -04:00
committed by GitHub
parent 30bd843130
commit 2d31d8bb3f
4 changed files with 31 additions and 9 deletions
@@ -175,6 +175,12 @@ To fix, update your pubspec.yaml to include the following:
throw ValidationFailedException();
}
if (validationIssuesContainsWarning(issues)) {
for (final issue in issues) {
logger.warn(issue.message);
}
}
}
/// Whether any [ValidationIssue]s have a severity of
@@ -182,6 +188,11 @@ To fix, update your pubspec.yaml to include the following:
bool validationIssuesContainsError(List<ValidationIssue> issues) =>
issues.any((issue) => issue.severity == ValidationIssueSeverity.error);
/// Whether any [ValidationIssue]s have a severity of
/// [ValidationIssueSeverity.warning].
bool validationIssuesContainsWarning(List<ValidationIssue> issues) =>
issues.any((issue) => issue.severity == ValidationIssueSeverity.warning);
/// Logs a message indicating that validation failed. If any of the issues
/// can be automatically fixed, this also prompts the user to run
/// `shorebird doctor --fix`.
@@ -23,7 +23,8 @@ class FlavorValidator extends Validator {
@override
Future<List<ValidationIssue>> validate() async {
final projectFlavors = shorebirdEnv.getShorebirdYaml()!.flavors;
final shorebirdYaml = shorebirdEnv.getShorebirdYaml()!;
final projectFlavors = shorebirdYaml.flavors;
if (projectFlavors == null && flavorArg != null) {
return [
ValidationIssue.error(
@@ -35,9 +36,11 @@ class FlavorValidator extends Validator {
if (projectFlavors != null && flavorArg == null) {
return [
ValidationIssue.error(
ValidationIssue.warning(
message:
'''The project has flavors ${projectFlavors.keys}, but no --flavor argument was provided''',
'''
The project has flavors ${projectFlavors.keys}, but no --flavor argument was provided.
The default app id ${shorebirdYaml.appId} will be used.''',
),
];
}
@@ -283,7 +283,7 @@ To fix, update your pubspec.yaml to include the following:
group('when platform supports flavors', () {
group('when no flavor is specified', () {
test('fails validation', () async {
test('logs warning and fails validation', () async {
await expectLater(
runWithOverrides(
() => shorebirdValidator.validateFlavors(
@@ -291,8 +291,15 @@ To fix, update your pubspec.yaml to include the following:
releasePlatform: ReleasePlatform.android,
),
),
throwsA(isA<ValidationFailedException>()),
completes,
);
verify(
() => logger.warn(
'''
The project has flavors (flavorA), but no --flavor argument was provided.
The default app id test will be used.''',
),
).called(1);
});
});
@@ -119,14 +119,15 @@ void main() {
validator = FlavorValidator(flavorArg: null);
});
test('returns validation error', () async {
test('returns validation warning', () async {
final issues = await runWithOverrides(validator.validate);
expect(
issues,
equals([
ValidationIssue.error(
message:
'''The project has flavors (flavorA, flavorB), but no --flavor argument was provided''',
ValidationIssue.warning(
message: '''
The project has flavors (flavorA, flavorB), but no --flavor argument was provided.
The default app id $appId will be used.''',
),
]),
);