chiark / gitweb /
cmdlistener: Break out write_error
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 May 2021 20:41:19 +0000 (21:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 May 2021 21:33:07 +0000 (22:33 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs

index 0aa83bd48ddafc78a391e9bd77522ec3b594dbd3..64ad89d1f446ff71860c464e10486c82a2566735 100644 (file)
@@ -1356,13 +1356,16 @@ impl CommandStream<'_> {
         },
         Err(EOF) => break,
         Err(IO(e)) => Err(e).context("read command stream")?,
-        Err(Parse(s)) => {
-          let resp = MgmtResponse::Error { error: ME::CommandParseFailed(s) };
-          self.chan.write.write(&resp).context("swrite command stream")?;
-        }
+        Err(Parse(s)) => self.write_error(ME::CommandParseFailed(s))?,
       }
     }
   }
+
+  #[throws(CSE)]
+  pub fn write_error(&mut self, error: MgmtError) {
+    let resp = MgmtResponse::Error { error };
+    self.chan.write.write(&resp).context("swrite error to command stream")?;
+  }
 }
 
 impl CommandStreamData<'_> {