From d76f08afbdce0643ffa6b74c9683a8f45541eec8 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 19 Aug 2024 11:37:42 +0200 Subject: [PATCH] Don't error on invalid `node_id` on `NodeConfig` request Instead, send the error back as reply. --- binaries/daemon/src/lib.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/binaries/daemon/src/lib.rs b/binaries/daemon/src/lib.rs index 0a2e5a29..be7c1d4a 100644 --- a/binaries/daemon/src/lib.rs +++ b/binaries/daemon/src/lib.rs @@ -724,16 +724,11 @@ impl Daemon { .count(); let node_config = match number_node_id { - 2.. => { - let _ = reply_tx.send(Some(DaemonReply::NodeConfig { - result: Err(format!( - "multiple dataflows contains dynamic node id {}. Please only have one running dataflow with the specified node id if you want to use dynamic node", - node_id - ) - .to_string()), - })); - return Ok(()); - } + 2.. => Err(format!( + "multiple dataflows contains dynamic node id {node_id}. \ + Please only have one running dataflow with the specified \ + node id if you want to use dynamic node", + )), 1 => self .running .iter() @@ -751,18 +746,18 @@ impl Daemon { Ok(node_config) }) .next() - .context("no node with ID `{node_id}`")? - .context("failed to get dynamic node config within given dataflow")?, - 0 => { - let _ = reply_tx.send(Some(DaemonReply::NodeConfig { - result: Err("no node with ID `{node_id}`".to_string()), - })); - return Ok(()); - } + .ok_or_else(|| eyre!("no node with ID `{node_id}`")) + .and_then(|r| r) + .map_err(|err| { + format!( + "failed to get dynamic node config within given dataflow: {err}" + ) + }), + 0 => Err("no node with ID `{node_id}`".to_string()), }; let reply = DaemonReply::NodeConfig { - result: Ok(node_config), + result: node_config, }; let _ = reply_tx.send(Some(reply)).map_err(|_| { error!("could not send node info reply from daemon to coordinator")