Skip to content

Commit

Permalink
merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Oct 17, 2024
1 parent 320960f commit 168fdfa
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions nexus/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,21 +673,35 @@ impl Nexus {
let external_server = self.external_server.lock().unwrap().take();
let mut res = Ok(());

let extend_err =
|mut res: &mut Result<(), String>, mut new: Result<(), String>| {
match (&mut res, &mut new) {
(Err(s), Err(new_err)) => {
s.push_str(&format!(", {new_err}"))
}
(Ok(()), Err(_)) => *res = new,
(_, Ok(())) => (),
}
};

if let Some(server) = external_server {
res = res.and(server.close().await);
extend_err(&mut res, server.close().await);
}
let techport_external_server =
self.techport_external_server.lock().unwrap().take();
if let Some(server) = techport_external_server {
res = res.and(server.close().await);
extend_err(&mut res, server.close().await);
}
let internal_server = self.internal_server.lock().unwrap().take();
if let Some(server) = internal_server {
res = res.and(server.close().await);
extend_err(&mut res, server.close().await);
}
let producer_server = self.producer_server.lock().unwrap().take();
if let Some(server) = producer_server {
res = res.and(server.close().await.map_err(|e| e.to_string()));
extend_err(
&mut res,
server.close().await.map_err(|e| e.to_string()),
);
}
res
}
Expand Down

0 comments on commit 168fdfa

Please sign in to comment.