vm-virtio: Fix map_err losing the inner error

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-01-24 09:31:52 +01:00
parent 4587cc7ffa
commit 0a7bcc9a7d
2 changed files with 9 additions and 3 deletions

View File

@ -28,12 +28,18 @@ mod defs {
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
/// Error converting from UTF-8
ConvertFromUTF8(std::str::Utf8Error),
/// Error registering a new epoll-listening FD. /// Error registering a new epoll-listening FD.
EpollAdd(std::io::Error), EpollAdd(std::io::Error),
/// Error creating an epoll FD. /// Error creating an epoll FD.
EpollFdCreate(std::io::Error), EpollFdCreate(std::io::Error),
/// The host made an invalid vsock port connection request. /// The host made an invalid vsock port connection request.
InvalidPortRequest, InvalidPortRequest,
/// Error parsing integer.
ParseInteger(std::num::ParseIntError),
/// Error reading stream port.
ReadStreamPort(Box<Error>),
/// Error accepting a new connection from the host-side Unix socket. /// Error accepting a new connection from the host-side Unix socket.
UnixAccept(std::io::Error), UnixAccept(std::io::Error),
/// Error binding to the host-side Unix socket. /// Error binding to the host-side Unix socket.

View File

@ -452,7 +452,7 @@ impl VsockMuxer {
} }
let mut word_iter = std::str::from_utf8(&buf[..blen]) let mut word_iter = std::str::from_utf8(&buf[..blen])
.map_err(|_| Error::InvalidPortRequest)? .map_err(Error::ConvertFromUTF8)?
.split_whitespace(); .split_whitespace();
word_iter word_iter
@ -466,8 +466,8 @@ impl VsockMuxer {
} }
}) })
.and_then(|_| word_iter.next().ok_or(Error::InvalidPortRequest)) .and_then(|_| word_iter.next().ok_or(Error::InvalidPortRequest))
.and_then(|word| word.parse::<u32>().map_err(|_| Error::InvalidPortRequest)) .and_then(|word| word.parse::<u32>().map_err(Error::ParseInteger))
.map_err(|_| Error::InvalidPortRequest) .map_err(|e| Error::ReadStreamPort(Box::new(e)))
} }
/// Add a new connection to the active connection pool. /// Add a new connection to the active connection pool.