Skip to content

Commit

Permalink
dont panic
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Aug 12, 2024
1 parent c2ef417 commit 41cc6a6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions nexus/src/app/sagas/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use super::NexusActionContext;
use super::{ActionRegistry, NexusSaga, SagaInitError};
use crate::app::sagas::declare_saga_actions;
use anyhow::ensure;
use omicron_common::api::external::Error;
use omicron_uuid_kinds::DemoSagaUuid;
use serde::Deserialize;
Expand Down Expand Up @@ -60,13 +61,16 @@ impl CompletingDemoSagas {
})
}

pub fn subscribe(&mut self, id: DemoSagaUuid) -> oneshot::Receiver<()> {
pub fn subscribe(
&mut self,
id: DemoSagaUuid,
) -> Result<oneshot::Receiver<()>, anyhow::Error> {
let (tx, rx) = oneshot::channel();
assert!(
ensure!(
self.ids.insert(id, tx).is_none(),
"multiple subscriptions for the same demo saga"
);
rx
Ok(rx)
}
}

Expand Down Expand Up @@ -111,7 +115,12 @@ async fn demo_wait(sagactx: NexusActionContext) -> Result<(), ActionError> {
.nexus()
.demo_sagas()
.map_err(ActionError::action_failed)?;
demo_sagas.subscribe(demo_id)
demo_sagas.subscribe(demo_id).map_err(|e| {
ActionError::action_failed(Error::internal_error(&format!(
"demo saga subscribe failed: {:#}",
e
)))
})?
};
match rx.await {
Ok(_) => {
Expand Down

0 comments on commit 41cc6a6

Please sign in to comment.