From aa5ae7616e3c141c817f0545e0177ca85ac251d9 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 24 Jan 2020 08:50:30 +0100 Subject: [PATCH] src: Fix map_err losing the inner error Signed-off-by: Sebastien Boeuf --- src/bin/vhost_user_fs.rs | 4 ++-- src/main.rs | 33 +++++++++++++++++---------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/bin/vhost_user_fs.rs b/src/bin/vhost_user_fs.rs index a6f120989..55c13f085 100644 --- a/src/bin/vhost_user_fs.rs +++ b/src/bin/vhost_user_fs.rs @@ -44,7 +44,7 @@ type VhostUserBackendResult = std::result::Result; #[derive(Debug)] enum Error { /// Failed to create kill eventfd. - CreateKillEventFd, + CreateKillEventFd(io::Error), /// Failed to handle event other than input event. HandleEventNotEpollIn, /// Failed to handle unknown event. @@ -89,7 +89,7 @@ impl VhostUserFsBackend { fn new(fs: F) -> Result { Ok(VhostUserFsBackend { mem: None, - kill_evt: EventFd::new(EFD_NONBLOCK).map_err(|_| Error::CreateKillEventFd)?, + kill_evt: EventFd::new(EFD_NONBLOCK).map_err(Error::CreateKillEventFd)?, server: Arc::new(Server::new(fs)), }) } diff --git a/src/main.rs b/src/main.rs index 5e36e5097..2df8c2266 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1918,18 +1918,17 @@ mod tests { let mut counter = 0; loop { match (|| -> Result<(), Error> { - let tcp = - TcpStream::connect(format!("{}:22", ip)).map_err(|_| Error::Connection)?; + let tcp = TcpStream::connect(format!("{}:22", ip)).map_err(Error::Connection)?; let mut sess = Session::new().unwrap(); sess.set_tcp_stream(tcp); - sess.handshake().map_err(|_| Error::Connection)?; + sess.handshake().map_err(Error::Handshake)?; sess.userauth_password("cloud", "cloud123") - .map_err(|_| Error::Authentication)?; + .map_err(Error::Authentication)?; assert!(sess.authenticated()); - let mut channel = sess.channel_session().map_err(|_| Error::Command)?; - channel.exec(command).map_err(|_| Error::Command)?; + let mut channel = sess.channel_session().map_err(Error::ChannelSession)?; + channel.exec(command).map_err(Error::Command)?; // Intentionally ignore these results here as their failure // does not precipitate a repeat @@ -1953,10 +1952,12 @@ mod tests { #[derive(Debug)] enum Error { - Connection, - Authentication, - Command, - Parsing, + Connection(std::io::Error), + Handshake(ssh2::Error), + Authentication(ssh2::Error), + ChannelSession(ssh2::Error), + Command(ssh2::Error), + Parsing(std::num::ParseIntError), } impl std::error::Error for Error {} @@ -2080,7 +2081,7 @@ mod tests { .ssh_command("grep -c processor /proc/cpuinfo")? .trim() .parse() - .map_err(|_| Error::Parsing)?) + .map_err(Error::Parsing)?) } fn get_initial_apicid(&self) -> Result { @@ -2088,7 +2089,7 @@ mod tests { .ssh_command("grep \"initial apicid\" /proc/cpuinfo | grep -o \"[0-9]*\"")? .trim() .parse() - .map_err(|_| Error::Parsing)?) + .map_err(Error::Parsing)?) } fn get_total_memory(&self) -> Result { @@ -2096,7 +2097,7 @@ mod tests { .ssh_command("grep MemTotal /proc/meminfo | grep -o \"[0-9]*\"")? .trim() .parse() - .map_err(|_| Error::Parsing)?) + .map_err(Error::Parsing)?) } fn get_entropy(&self) -> Result { @@ -2104,7 +2105,7 @@ mod tests { .ssh_command("cat /proc/sys/kernel/random/entropy_avail")? .trim() .parse() - .map_err(|_| Error::Parsing)?) + .map_err(Error::Parsing)?) } fn get_pci_bridge_class(&self) -> Result { @@ -2189,8 +2190,8 @@ mod tests { return Ok(false); } - let start_addr = u64::from_str_radix(args[0], 16).map_err(|_| Error::Parsing)?; - let end_addr = u64::from_str_radix(args[1], 16).map_err(|_| Error::Parsing)?; + let start_addr = u64::from_str_radix(args[0], 16).map_err(Error::Parsing)?; + let end_addr = u64::from_str_radix(args[1], 16).map_err(Error::Parsing)?; Ok(cache == (end_addr - start_addr + 1)) }