Skip to content

Commit

Permalink
fix(cli): fix for meta-cli deploy exit with code 0 on failure (#600)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
destifo committed Feb 27, 2024
1 parent fffe530 commit 169e5f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion meta-cli/src/cli/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
27 changes: 26 additions & 1 deletion meta-cli/src/deploy/actors/push_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
})
}
Expand All @@ -90,6 +91,7 @@ pub struct PushManagerActor {
typegraph_paths: HashMap<String, PathBuf>,
// maps: typegraph_key -> option
one_time_push_options: HashMap<String, Vec<OneTimePushOption>>,
failed_push_exists: bool,
}

impl PushManagerActor {
Expand Down Expand Up @@ -363,6 +365,9 @@ impl Handler<PushFinished> 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 {
Expand Down Expand Up @@ -412,6 +417,20 @@ impl Handler<Stop> for PushManagerActor {
}
}

#[derive(Message)]
#[rtype(result = "()")]
struct SendBackFailedStatus {
failure_tx: oneshot::Sender<bool>,
}

impl Handler<SendBackFailedStatus> 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 {
Expand Down Expand Up @@ -441,7 +460,13 @@ impl PushManager for Addr<PushManagerActor> {
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<()> {
Expand Down
1 change: 1 addition & 0 deletions typegate/tests/e2e/cli/deploy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Meta.test(
});

try {
await reset("e2e7895alt");
await deploy(port);
} catch (e) {
assertStringIncludes(
Expand Down

0 comments on commit 169e5f4

Please sign in to comment.