From 13a5c68532b7da6206b06dabb9fe09d0984a36bb Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 14 May 2022 19:58:25 +0100 Subject: [PATCH] support: Rename PacketFrame errors That's what they are. Signed-off-by: Ian Jackson --- daemon/cmdlistener.rs | 2 +- support/imports.rs | 2 +- support/packetframe.rs | 40 ++++++++++++++++++++-------------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 00b33521..5c651cd2 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -1442,7 +1442,7 @@ impl CommandStream<'_> { #[throws(CSE)] pub fn mainloop(&mut self) { loop { - use MgmtChannelReadError::*; + use PacketFrameReadError::*; match { self.chan.read.inner_mut().set_timeout(Some(IDLE_TIMEOUT)); let r = self.chan.read.read_withbulk::(); diff --git a/support/imports.rs b/support/imports.rs index c58026ed..c2c7c11a 100644 --- a/support/imports.rs +++ b/support/imports.rs @@ -58,7 +58,7 @@ pub use crate::childio; pub use crate::debugmutex::DebugIdentify; pub use crate::packetframe::{FrameReader, FrameWriter, ReadFrame, WriteFrame}; pub use crate::packetframe::{ReadExt, ResponseWriter}; -pub use crate::packetframe::{MgmtChannelReadError, MgmtChannelWriteError}; +pub use crate::packetframe::{PacketFrameReadError, PacketFrameWriteError}; pub use crate::progress::{self, ProgressInfo, OriginatorExt as _}; pub use crate::support::*; pub use crate::termprogress; diff --git a/support/packetframe.rs b/support/packetframe.rs index ad2ffe3f..74fbb5a7 100644 --- a/support/packetframe.rs +++ b/support/packetframe.rs @@ -18,29 +18,29 @@ use crate::prelude::*; // ---------- errors (MgmtChannel, anomalous name) ---------- #[derive(Debug,Error)] -pub enum MgmtChannelReadError { +pub enum PacketFrameReadError { #[error("unexpected EOF")] EOF, #[error("parse MessagePack: {0}")] Parse(String), #[error("{0}")] IO(#[from] io::Error), } #[derive(Debug,Error)] -pub enum MgmtChannelWriteError { +pub enum PacketFrameWriteError { Serialize(rmp_serde::encode::Error), // but not ValueWriteError so no from IO(#[from] io::Error), } -display_as_debug!{MgmtChannelWriteError} +display_as_debug!{PacketFrameWriteError} -impl From for MgmtChannelWriteError { - fn from(re: rmp_serde::encode::Error) -> MgmtChannelWriteError { +impl From for PacketFrameWriteError { + fn from(re: rmp_serde::encode::Error) -> PacketFrameWriteError { use rmp_serde::encode::Error::*; - use MgmtChannelWriteError as MCWE; + use PacketFrameWriteError as PFWE; use rmp::encode::ValueWriteError as RVWE; match re { - InvalidValueWrite(RVWE::InvalidMarkerWrite(ioe)) => MCWE::IO(ioe), - InvalidValueWrite(RVWE::InvalidDataWrite (ioe)) => MCWE::IO(ioe), + InvalidValueWrite(RVWE::InvalidMarkerWrite(ioe)) => PFWE::IO(ioe), + InvalidValueWrite(RVWE::InvalidDataWrite (ioe)) => PFWE::IO(ioe), ser@ (UnknownLength | InvalidDataModel(_) | - DepthLimitExceeded | Syntax(_)) => MCWE::Serialize(ser), + DepthLimitExceeded | Syntax(_)) => PFWE::Serialize(ser), } } } @@ -326,17 +326,17 @@ impl FrameReader { } } - #[throws(MgmtChannelReadError)] + #[throws(PacketFrameReadError)] pub fn read_withbulk<'c,T>(&'c mut self) -> (T, ReadFrame<'c,R>) where T: DeserializeOwned + Debug { - let mut f = self.new_frame()?.ok_or(MgmtChannelReadError::EOF)?; + let mut f = self.new_frame()?.ok_or(PacketFrameReadError::EOF)?; let v = f.read_rmp()?; trace!("read OK {:?}", &v); (v, f) } - #[throws(MgmtChannelReadError)] + #[throws(PacketFrameReadError)] pub fn read(&mut self) -> T where T: DeserializeOwned + Debug { @@ -354,14 +354,14 @@ impl<'r,R:Read> ReadFrame<'r,R> { #[ext(pub, name=ReadExt)] impl R { - #[throws(MgmtChannelReadError)] + #[throws(PacketFrameReadError)] fn read_rmp(&mut self) -> T where T: DeserializeOwned, R: Read { - use MgmtChannelReadError as MCRE; + use PacketFrameReadError as PFRE; let r = rmp_serde::decode::from_read(self); - let v = r.map_err(|e| MCRE::Parse(format!("{}", &e)))?; + let v = r.map_err(|e| PFRE::Parse(format!("{}", &e)))?; v } } @@ -431,12 +431,12 @@ impl FrameWriter { } } - #[throws(MgmtChannelWriteError)] + #[throws(PacketFrameWriteError)] pub fn write_withbulk<'c>(&'c mut self) -> ResponseWriter<'c,W> { ResponseWriter { f: self.new_frame()? } } - #[throws(MgmtChannelWriteError)] + #[throws(PacketFrameWriteError)] pub fn write(&mut self, val: &T) where T: Serialize + Debug { @@ -488,7 +488,7 @@ impl<'w,W:Write> Write for WriteFrame<'w,W> { pub struct ResponseWriter<'c,W:Write> { f: WriteFrame<'c,W> } impl<'c,W:Write> ResponseWriter<'c,W> { - #[throws(MgmtChannelWriteError)] + #[throws(PacketFrameWriteError)] pub fn respond<'t,T>(mut self, val: &'t T) -> WriteFrame<'c,W> where T: Serialize + Debug { @@ -497,13 +497,13 @@ impl<'c,W:Write> ResponseWriter<'c,W> { self.f } - #[throws(MgmtChannelWriteError)] + #[throws(PacketFrameWriteError)] pub fn progress_with(&mut self, resp: RESP) { rmp_serde::encode::write_named(&mut self.f, &resp)?; self.f.flush()?; } /* - #[throws(MgmtChannelWriteError)] + #[throws(PacketFrameWriteError)] pub fn progress(&mut self, pi: ProgressInfo<'_>) { let resp = crate::commands::MgmtResponse::Progress(pi.into_owned()); rmp_serde::encode::write_named(&mut self.f, &resp)?; -- 2.30.2