From 4021912be84d2467c9d7e1a9af02472a4f656dc7 Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 14 Jun 2024 15:18:52 -0300 Subject: [PATCH] fix: gracefully handling patching on a app with no releases (#2247) Co-authored-by: Bryan Oltman --- .../lib/src/commands/patch/patch_command.dart | 8 +++++++ .../commands/patch/patch_command_test.dart | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart index 056e6840..50aa2fd8 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart @@ -308,6 +308,14 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl final releases = await codePushClientWrapper.getReleases( appId: appId, ); + + if (releases.isEmpty) { + logger.warn( + '''No releases found for app $appId. You need to make first a release before you can create a patch.''', + ); + throw ProcessExit(ExitCode.usage.code); + } + return logger.chooseOne( 'Which release would you like to patch?', choices: releases.sortedBy((r) => r.createdAt).reversed.toList(), diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart index 95ca3670..dcc3157e 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart @@ -678,6 +678,27 @@ void main() { ); }); + group('when prompting for releases, but there is none', () { + setUp(() { + when( + () => codePushClientWrapper.getReleases(appId: any(named: 'appId')), + ).thenAnswer((_) async => []); + }); + + test('warns and exits', () async { + await expectLater( + () => runWithOverrides(command.run), + exitsWithCode(ExitCode.usage), + ); + + verify( + () => logger.warn( + '''No releases found for app $appId. You need to make first a release before you can create a patch.''', + ), + ).called(1); + }); + }); + group('when running on CI', () { setUp(() { when(() => shorebirdEnv.canAcceptUserInput).thenReturn(false);