Merge remote-tracking branch 'upstream/master' into poll

This commit is contained in:
Marcin Mielniczuk
2020-01-17 08:55:42 +01:00
57 changed files with 1134 additions and 1077 deletions

View File

@@ -8,7 +8,7 @@ use thiserror::Error;
#[derive(Clone, Copy, Debug, Error, Eq, PartialEq)]
#[repr(u16)]
#[error("{:?}", self)]
#[error("{:?} ({})", self, wasi::strerror(*self as wasi::__wasi_errno_t))]
pub enum WasiError {
ESUCCESS = wasi::__WASI_ERRNO_SUCCESS,
E2BIG = wasi::__WASI_ERRNO_2BIG,
@@ -104,14 +104,11 @@ pub enum Error {
#[cfg(unix)]
#[error("Yanix error: {0}")]
Yanix(#[from] yanix::YanixError),
#[cfg(windows)]
#[error("Winx error: {0}")]
Winx(#[from] winx::winerror::WinError),
}
impl From<TryFromIntError> for Error {
fn from(_: TryFromIntError) -> Self {
Self::Wasi(WasiError::EOVERFLOW)
Self::EOVERFLOW
}
}
@@ -123,39 +120,46 @@ impl From<Infallible> for Error {
impl From<str::Utf8Error> for Error {
fn from(_: str::Utf8Error) -> Self {
Self::Wasi(WasiError::EILSEQ)
Self::EILSEQ
}
}
impl From<ffi::NulError> for Error {
fn from(_: ffi::NulError) -> Self {
Self::Wasi(WasiError::EILSEQ)
Self::EILSEQ
}
}
impl From<&ffi::NulError> for Error {
fn from(_: &ffi::NulError) -> Self {
Self::Wasi(WasiError::EILSEQ)
Self::EILSEQ
}
}
impl Error {
pub(crate) fn as_wasi_errno(&self) -> wasi::__wasi_errno_t {
pub(crate) fn as_wasi_error(&self) -> WasiError {
match self {
Self::Wasi(no) => no.as_raw_errno(),
Self::Io(e) => errno_from_ioerror(e.to_owned()),
Self::Wasi(err) => *err,
Self::Io(err) => {
let err = match err.raw_os_error() {
Some(code) => Self::from_raw_os_error(code),
None => {
log::debug!("Inconvertible OS error: {}", err);
Self::EIO
}
};
err.as_wasi_error()
}
#[cfg(unix)]
Self::Yanix(err) => {
use yanix::YanixError::*;
let err = match err {
Errno(errno) => crate::sys::host_impl::errno_from_nix(*errno),
let err: Self = match err {
Errno(errno) => (*errno).into(),
NulError(err) => err.into(),
TryFromIntError(err) => (*err).into(),
};
err.as_wasi_errno()
err.as_wasi_error()
}
#[cfg(windows)]
Self::Winx(err) => crate::sys::host_impl::errno_from_win(*err),
}
}
@@ -238,14 +242,8 @@ impl Error {
pub const ENOTCAPABLE: Self = Error::Wasi(WasiError::ENOTCAPABLE);
}
fn errno_from_ioerror(e: &std::io::Error) -> wasi::__wasi_errno_t {
match e.raw_os_error() {
Some(code) => crate::sys::errno_from_host(code),
None => {
log::debug!("Inconvertible OS error: {}", e);
wasi::__WASI_ERRNO_IO
}
}
pub(crate) trait FromRawOsError {
fn from_raw_os_error(code: i32) -> Self;
}
pub(crate) type Result<T> = std::result::Result<T, Error>;