From 22fcbca29482edd4f4138b67fe6d9bdcd3cc45f1 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Thu, 16 Jan 2025 15:50:48 -0600 Subject: [PATCH] chore(shorebird_cli): improve error message when Flutter project does not support macOS --- .../macos_network_entitlement_validator.dart | 9 +++++++-- .../macos_network_entitlement_validator_test.dart | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/shorebird_cli/lib/src/validators/macos_network_entitlement_validator.dart b/packages/shorebird_cli/lib/src/validators/macos_network_entitlement_validator.dart index 2831fc3b6..09467a5cf 100644 --- a/packages/shorebird_cli/lib/src/validators/macos_network_entitlement_validator.dart +++ b/packages/shorebird_cli/lib/src/validators/macos_network_entitlement_validator.dart @@ -48,8 +48,13 @@ class MacosNetworkEntitlementValidator extends Validator { String get description => 'macOS app has Outgoing Connections entitlement'; @override - bool canRunInCurrentContext() => - _macosDirectory != null && _macosDirectory!.existsSync(); + bool canRunInCurrentContext() => _macosDirectory?.existsSync() ?? false; + + @override + String? get incorrectContextMessage => ''' +The ${_macosDirectory?.path ?? 'macos'} directory does not exist. + +The command you are running must be run within a Flutter app project that supports the macOS platform.'''; @override Future> validate() async { diff --git a/packages/shorebird_cli/test/src/validators/macos_network_entitlement_validator_test.dart b/packages/shorebird_cli/test/src/validators/macos_network_entitlement_validator_test.dart index 7468bec91..6ebb70946 100644 --- a/packages/shorebird_cli/test/src/validators/macos_network_entitlement_validator_test.dart +++ b/packages/shorebird_cli/test/src/validators/macos_network_entitlement_validator_test.dart @@ -91,6 +91,10 @@ void main() { runWithOverrides(() => validator.canRunInCurrentContext()), isTrue, ); + expect( + runWithOverrides(() => validator.incorrectContextMessage), + isNull, + ); }); }); @@ -100,6 +104,12 @@ void main() { runWithOverrides(() => validator.canRunInCurrentContext()), isFalse, ); + expect( + runWithOverrides(() => validator.incorrectContextMessage), + contains( + '''The command you are running must be run within a Flutter app project that supports the macOS platform.''', + ), + ); }); }); });