From 6856942b9c70d8b69c4cc663afbcab3782a45d39 Mon Sep 17 00:00:00 2001 From: Kazi Waseef Date: Wed, 13 Dec 2023 17:55:10 +0600 Subject: [PATCH] fix(globe_cli): Bad state no element error on deployment fixed (#8) * fix: Bad state no element error on deployment fixed * fix: typo deployProgess to deployProgress * fix: add invalid status and status check for DeploymentEnvironment and DeploymentState * chore: added archiver to wordlist --- .github/.cspell/words_dictionary.txt | 3 ++- .../lib/src/commands/deploy_command.dart | 18 +++++++++++++----- packages/globe_cli/lib/src/utils/api.dart | 14 +++++++++++--- packages/globe_cli/pubspec.lock | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/.cspell/words_dictionary.txt b/.github/.cspell/words_dictionary.txt index 082e1de5..c45d42b0 100644 --- a/.github/.cspell/words_dictionary.txt +++ b/.github/.cspell/words_dictionary.txt @@ -1,2 +1,3 @@ # Actual english words (or common abbreviations) missing from CSpell -upvote \ No newline at end of file +upvote +archiver diff --git a/packages/globe_cli/lib/src/commands/deploy_command.dart b/packages/globe_cli/lib/src/commands/deploy_command.dart index f5d804a9..23b98dcb 100644 --- a/packages/globe_cli/lib/src/commands/deploy_command.dart +++ b/packages/globe_cli/lib/src/commands/deploy_command.dart @@ -45,7 +45,7 @@ class DeployCommand extends BaseGlobeCommand { final validated = await scope.validate(); - final deployProgess = logger.progress( + final deployProgress = logger.progress( 'Deploying to ${styleBold.wrap('${validated.organization.slug}/${validated.project.slug}')}${environment == DeploymentEnvironment.production ? ' (production)' : ''}', ); @@ -63,7 +63,7 @@ class DeployCommand extends BaseGlobeCommand { archive: archive, ); - deployProgess.complete(); + deployProgress.complete(); logger.success( '${lightGreen.wrap('✓')} Deployment has been queued', @@ -85,7 +85,8 @@ class DeployCommand extends BaseGlobeCommand { deploymentId: deployment.id, ); - if (update.state == DeploymentState.working) { + if (update.state == DeploymentState.working || + update.state == DeploymentState.deploying) { if (logs != null) return; status.complete(); @@ -136,6 +137,13 @@ class DeployCommand extends BaseGlobeCommand { logger.info('Deployment cancelled'); } + if (update.state == DeploymentState.invalid) { + status.complete(); + status = logger.progress( + 'Invalid Deployment State Received. Waiting for valid state', + ); + } + if (update.state == DeploymentState.success || update.state == DeploymentState.cancelled || update.state == DeploymentState.error) { @@ -148,11 +156,11 @@ class DeployCommand extends BaseGlobeCommand { return ExitCode.success.code; } on ApiException catch (e) { - deployProgess.fail(); + deployProgress.fail(); logger.err('✗ Failed to deploy project: ${e.message}'); return ExitCode.software.code; } catch (e, s) { - deployProgess.fail(); + deployProgress.fail(); logger ..err('✗ Failed to deploy project: $e') ..err(s.toString()); diff --git a/packages/globe_cli/lib/src/utils/api.dart b/packages/globe_cli/lib/src/utils/api.dart index d62c145c..7b17c689 100644 --- a/packages/globe_cli/lib/src/utils/api.dart +++ b/packages/globe_cli/lib/src/utils/api.dart @@ -436,9 +436,13 @@ class Deployment { projectId: projectId, environment: DeploymentEnvironment.values.firstWhere( (e) => e.name == environment, + orElse: () => DeploymentEnvironment.invalid, ), status: status, - state: DeploymentState.values.firstWhere((e) => e.name == state), + state: DeploymentState.values.firstWhere( + (e) => e.name == state, + orElse: () => DeploymentState.invalid, + ), message: message ?? '', url: url, hash: hash, @@ -466,9 +470,12 @@ class Deployment { enum DeploymentState { pending('Queued'), working('In progress'), + deploying('Deploying'), success('Deployment successful'), error('Deployment failed'), - cancelled('Deployment cancelled'); + cancelled('Deployment cancelled'), + // state is not a valid state, but is used to represent an invalid state. + invalid('Invalid'); const DeploymentState(this.message); @@ -518,7 +525,8 @@ class FrameworkPresetOptions { enum DeploymentEnvironment { preview, - production; + production, + invalid; } enum Role { diff --git a/packages/globe_cli/pubspec.lock b/packages/globe_cli/pubspec.lock index 566b78f2..b4591009 100644 --- a/packages/globe_cli/pubspec.lock +++ b/packages/globe_cli/pubspec.lock @@ -247,7 +247,7 @@ packages: path: "../globe_lints" relative: true source: path - version: "1.0.0" + version: "1.0.1" graphs: dependency: transitive description: