From 169e5f402ea04372a23deaf0a44fbaa45a7cf0b7 Mon Sep 17 00:00:00 2001 From: Estifanos Bireda <77430541+destifo@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:50:35 +0300 Subject: [PATCH] fix(cli): fix for `meta-cli deploy` exit with code `0` on failure (#600) fix the issue where `meta-cli deploy` command exits with code 0 on failure. #### Motivation and context bug fix #### Migration notes No changes needed. ### Checklist - [ ] The change come with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change --- meta-cli/src/cli/deploy.rs | 6 ++++- meta-cli/src/deploy/actors/push_manager.rs | 27 +++++++++++++++++++++- typegate/tests/e2e/cli/deploy_test.ts | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/meta-cli/src/cli/deploy.rs b/meta-cli/src/cli/deploy.rs index c37b2d2da..dc7c6708f 100644 --- a/meta-cli/src/cli/deploy.rs +++ b/meta-cli/src/cli/deploy.rs @@ -259,7 +259,11 @@ mod default_mode { }; log::debug!("loader stopped, stopping pusher"); - pusher.stop().await?; + let result = pusher.stop().await; + if let Err(e) = result { + System::current().stop_with_code(1); + return Err(e); + } ret } diff --git a/meta-cli/src/deploy/actors/push_manager.rs b/meta-cli/src/deploy/actors/push_manager.rs index a6357ccea..2f22ec11f 100644 --- a/meta-cli/src/deploy/actors/push_manager.rs +++ b/meta-cli/src/deploy/actors/push_manager.rs @@ -72,6 +72,7 @@ impl PushManagerBuilder { retry_config: self.retry_config, typegraph_paths: HashMap::new(), one_time_push_options: HashMap::new(), + failed_push_exists: false, } }) } @@ -90,6 +91,7 @@ pub struct PushManagerActor { typegraph_paths: HashMap, // maps: typegraph_key -> option one_time_push_options: HashMap>, + failed_push_exists: bool, } impl PushManagerActor { @@ -363,6 +365,9 @@ impl Handler for PushManagerActor { name = name.cyan() )); } + if !self.failed_push_exists { + self.failed_push_exists = !msg.success; + } let res = self.remove_active(&msg.push.typegraph); let Some(CancelationStatus(is_cancelled)) = res else { @@ -412,6 +417,20 @@ impl Handler for PushManagerActor { } } +#[derive(Message)] +#[rtype(result = "()")] +struct SendBackFailedStatus { + failure_tx: oneshot::Sender, +} + +impl Handler for PushManagerActor { + type Result = (); + + fn handle(&mut self, msg: SendBackFailedStatus, _ctx: &mut Self::Context) -> Self::Result { + msg.failure_tx.send(self.failed_push_exists).unwrap(); + } +} + #[derive(Message)] #[rtype(result = "()")] struct CancelAllFromModule { @@ -441,7 +460,13 @@ impl PushManager for Addr { self.do_send(Stop { tx }); rx.await?; log::trace!("PushManager stopped"); - Ok(()) + let (failure_tx, failure_rx) = oneshot::channel(); + self.do_send(SendBackFailedStatus { failure_tx }); + let failed = failure_rx.await.unwrap(); + match failed { + false => Ok(()), + true => Err(anyhow::anyhow!("Pushing one or more typegraphs failed")), + } } async fn cancel_all_from(&self, path: &Path) -> Result<()> { diff --git a/typegate/tests/e2e/cli/deploy_test.ts b/typegate/tests/e2e/cli/deploy_test.ts index 75f72e721..c322f010b 100644 --- a/typegate/tests/e2e/cli/deploy_test.ts +++ b/typegate/tests/e2e/cli/deploy_test.ts @@ -114,6 +114,7 @@ Meta.test( }); try { + await reset("e2e7895alt"); await deploy(port); } catch (e) { assertStringIncludes(