wasi-common: instead of panicking, use an Error::Unsupported that Traps

This commit is contained in:
Pat Hickey
2021-01-07 14:05:49 -08:00
parent 030f01345a
commit b149a03d5d
5 changed files with 59 additions and 49 deletions

View File

@@ -724,7 +724,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
}
fn proc_raise(&self, _sig: types::Signal) -> Result<()> {
unimplemented!("proc_raise")
Err(Error::Unsupported("proc_raise"))
}
fn sched_yield(&self) -> Result<()> {
@@ -744,7 +744,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
_ri_data: &types::IovecArray<'_>,
_ri_flags: types::Riflags,
) -> Result<(types::Size, types::Roflags)> {
unimplemented!("sock_recv")
Err(Error::Unsupported("sock_recv"))
}
fn sock_send(
@@ -753,11 +753,11 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
_si_data: &types::CiovecArray<'_>,
_si_flags: types::Siflags,
) -> Result<types::Size> {
unimplemented!("sock_send")
Err(Error::Unsupported("sock_send"))
}
fn sock_shutdown(&self, _fd: types::Fd, _how: types::Sdflags) -> Result<()> {
unimplemented!("sock_shutdown")
Err(Error::Unsupported("sock_shutdown"))
}
}
@@ -804,7 +804,7 @@ impl WasiCtx {
Err(error) => {
events.push(types::Event {
userdata: subscription.userdata,
error: error.into(),
error: error.try_into().expect("non-trapping error"),
type_: types::Eventtype::FdRead,
fd_readwrite: types::EventFdReadwrite {
nbytes: 0,
@@ -830,7 +830,7 @@ impl WasiCtx {
Err(error) => {
events.push(types::Event {
userdata: subscription.userdata,
error: error.into(),
error: error.try_into().expect("non-trapping error"),
type_: types::Eventtype::FdWrite,
fd_readwrite: types::EventFdReadwrite {
nbytes: 0,

View File

@@ -25,13 +25,14 @@ impl types::GuestErrorConversion for WasiCtx {
impl types::UserErrorConversion for WasiCtx {
fn errno_from_error(&self, e: Error) -> Result<Errno, wiggle::Trap> {
tracing::debug!("Error: {:?}", e);
Ok(e.into())
e.try_into()
}
}
impl From<Error> for Errno {
fn from(e: Error) -> Errno {
types_new::Errno::from(e).into()
impl TryFrom<Error> for Errno {
type Error = wiggle::Trap;
fn try_from(e: Error) -> Result<Errno, wiggle::Trap> {
Ok(types_new::Errno::try_from(e)?.into())
}
}