From 8839eb0af47b99511956d81a6dbb32e948d2076c Mon Sep 17 00:00:00 2001 From: A-Walrus <58790821+A-Walrus@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:36:04 +0300 Subject: [PATCH] Fix unwrap bug in DAP (#6786) --- helix-dap/src/client.rs | 10 +++----- helix-dap/src/transport.rs | 46 +++++++++++++++++++++------------- helix-view/src/handlers/dap.rs | 1 + 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 7efb72d80..acdfc5b7e 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -62,12 +62,10 @@ impl Client { if command.is_empty() { return Result::Err(Error::Other(anyhow!("Command not provided"))); } - if transport == "tcp" && port_arg.is_some() { - Self::tcp_process(command, args, port_arg.unwrap(), id).await - } else if transport == "stdio" { - Self::stdio(command, args, id) - } else { - Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport))) + match (transport, port_arg) { + ("tcp", Some(port_arg)) => Self::tcp_process(command, args, port_arg, id).await, + ("stdio", _) => Self::stdio(command, args, id), + _ => Result::Err(Error::Other(anyhow!("Incorrect transport {}", transport))), } } diff --git a/helix-dap/src/transport.rs b/helix-dap/src/transport.rs index dd03e5685..0f646b6a4 100644 --- a/helix-dap/src/transport.rs +++ b/helix-dap/src/transport.rs @@ -230,38 +230,48 @@ impl Transport { } } - async fn recv( + async fn recv_inner( transport: Arc, mut server_stdout: Box, client_tx: UnboundedSender, - ) { + ) -> Result<()> { let mut recv_buffer = String::new(); loop { - match Self::recv_server_message(&mut server_stdout, &mut recv_buffer).await { - Ok(msg) => { - transport - .process_server_message(&client_tx, msg) - .await - .unwrap(); - } - Err(err) => { - error!("err: <- {:?}", err); - break; - } - } + let msg = Self::recv_server_message(&mut server_stdout, &mut recv_buffer).await?; + transport.process_server_message(&client_tx, msg).await?; } } - async fn send( + async fn recv( + transport: Arc, + server_stdout: Box, + client_tx: UnboundedSender, + ) { + if let Err(err) = Self::recv_inner(transport, server_stdout, client_tx).await { + error!("err: <- {:?}", err); + } + } + + async fn send_inner( transport: Arc, mut server_stdin: Box, mut client_rx: UnboundedReceiver, - ) { + ) -> Result<()> { while let Some(payload) = client_rx.recv().await { transport .send_payload_to_server(&mut server_stdin, payload) - .await - .unwrap() + .await?; + } + Ok(()) + } + + async fn send( + transport: Arc, + server_stdin: Box, + client_rx: UnboundedReceiver, + ) { + if let Err(err) = Self::send_inner(transport, server_stdin, client_rx).await { + error!("err: <- {:?}", err); } } diff --git a/helix-view/src/handlers/dap.rs b/helix-view/src/handlers/dap.rs index 107c29be5..3da01494d 100644 --- a/helix-view/src/handlers/dap.rs +++ b/helix-view/src/handlers/dap.rs @@ -321,6 +321,7 @@ impl Editor { } } None => { + self.debugger = None; self.set_status( "Terminated debugging session and disconnected debugger.", );