unexpected io error: do our best based on e.kind()

This commit is contained in:
Pat Hickey
2020-12-17 18:12:15 -08:00
parent f9ff97aac1
commit d8720cffe8
2 changed files with 22 additions and 5 deletions

View File

@@ -34,9 +34,6 @@ pub enum Error {
#[error("Unexpected IoError: {0}")] #[error("Unexpected IoError: {0}")]
UnexpectedIo(#[source] std::io::Error), UnexpectedIo(#[source] std::io::Error),
#[error("Unsupported operation: {0}")]
Unsupported(String),
// Below this, all variants are from the `$errno` type: // Below this, all variants are from the `$errno` type:
/// Errno::TooBig: Argument list too long /// Errno::TooBig: Argument list too long
#[error("TooBig: Argument list too long")] #[error("TooBig: Argument list too long")]

View File

@@ -38,12 +38,33 @@ impl types::UserErrorConversion for WasiCtx {
impl From<Error> for types::Errno { impl From<Error> for types::Errno {
fn from(e: Error) -> types::Errno { fn from(e: Error) -> types::Errno {
use std::io::ErrorKind;
use types::Errno; use types::Errno;
match e { match e {
Error::Guest(e) => e.into(), Error::Guest(e) => e.into(),
Error::TryFromInt(_) => Errno::Overflow, Error::TryFromInt(_) => Errno::Overflow,
Error::Utf8(_) => Errno::Ilseq, Error::Utf8(_) => Errno::Ilseq,
Error::UnexpectedIo(_) => Errno::Io, Error::UnexpectedIo(e) => match e.kind() {
ErrorKind::NotFound => Errno::Noent,
ErrorKind::PermissionDenied => Errno::Perm,
ErrorKind::AlreadyExists => Errno::Exist,
ErrorKind::InvalidInput => Errno::Ilseq,
ErrorKind::ConnectionRefused
| ErrorKind::ConnectionReset
| ErrorKind::ConnectionAborted
| ErrorKind::NotConnected
| ErrorKind::AddrInUse
| ErrorKind::AddrNotAvailable
| ErrorKind::BrokenPipe
| ErrorKind::WouldBlock
| ErrorKind::InvalidData
| ErrorKind::TimedOut
| ErrorKind::WriteZero
| ErrorKind::Interrupted
| ErrorKind::Other
| ErrorKind::UnexpectedEof
| _ => Errno::Io,
},
Error::GetRandom(_) => Errno::Io, Error::GetRandom(_) => Errno::Io,
Error::TooBig => Errno::TooBig, Error::TooBig => Errno::TooBig,
Error::Acces => Errno::Acces, Error::Acces => Errno::Acces,
@@ -75,7 +96,6 @@ impl From<Error> for types::Errno {
Error::DirNotCapable { .. } => Errno::Notcapable, Error::DirNotCapable { .. } => Errno::Notcapable,
Error::NotCapable => Errno::Notcapable, Error::NotCapable => Errno::Notcapable,
Error::TableOverflow => Errno::Overflow, Error::TableOverflow => Errno::Overflow,
Error::Unsupported { .. } => Errno::Notcapable, // XXX is this reasonable?
} }
} }
} }