Use wiggle "trappable error" to implement wasi-common (#5279)

* convert wasi-common from defining its own error to using wiggle trappable error

* wasi-common impl crates: switch error strategy

* wasmtime-wasi: error is trappable, and no longer requires UserErrorConversion

* docs

* typo

* readdir: windows fixes

* fix windows scheduler errors

fun fact! the Send and Recv errors here that just had a `.context` on
them were previously not being captured in the downcasting either. They
need to be traps, and would have ended up that way by ommission, but
you'd never actually know that by reading the code!
This commit is contained in:
Pat Hickey
2022-11-16 16:57:22 -08:00
committed by GitHub
parent de6e4a4e20
commit 56daa8a199
12 changed files with 461 additions and 467 deletions

View File

@@ -8,7 +8,6 @@
// We suspect there are bugs in this scheduler, however, we have not
// taken the time to improve it. See bug #2880.
use anyhow::Context;
use once_cell::sync::Lazy;
use std::ops::Deref;
use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender, TryRecvError};
@@ -73,7 +72,7 @@ pub async fn poll_oneoff_<'a>(
if !stdin_read_subs.is_empty() {
let state = STDIN_POLL
.lock()
.map_err(|_| Error::trap("failed to take lock of STDIN_POLL"))?
.map_err(|_| Error::trap(anyhow::Error::msg("failed to take lock of STDIN_POLL")))?
.poll(waitmode)?;
for readsub in stdin_read_subs.into_iter() {
match state {
@@ -167,34 +166,36 @@ impl StdinPoll {
// Clean up possibly unread result from previous poll.
Ok(_) | Err(TryRecvError::Empty) => {}
Err(TryRecvError::Disconnected) => {
return Err(Error::trap("StdinPoll notify_rx channel closed"))
return Err(Error::trap(anyhow::Error::msg(
"StdinPoll notify_rx channel closed",
)))
}
}
// Notify the worker thread to poll stdin
self.request_tx
.send(())
.context("request_tx channel closed")?;
.map_err(|_| Error::trap(anyhow::Error::msg("request_tx channel closed")))?;
// Wait for the worker thread to send a readiness notification
match wait_mode {
WaitMode::Timeout(timeout) => match self.notify_rx.recv_timeout(timeout) {
Ok(r) => Ok(r),
Err(RecvTimeoutError::Timeout) => Ok(PollState::TimedOut),
Err(RecvTimeoutError::Disconnected) => {
Err(Error::trap("StdinPoll notify_rx channel closed"))
}
Err(RecvTimeoutError::Disconnected) => Err(Error::trap(anyhow::Error::msg(
"StdinPoll notify_rx channel closed",
))),
},
WaitMode::Infinite => self
.notify_rx
.recv()
.context("StdinPoll notify_rx channel closed"),
.map_err(|_| Error::trap(anyhow::Error::msg("StdinPoll notify_rx channel closed"))),
WaitMode::Immediate => match self.notify_rx.try_recv() {
Ok(r) => Ok(r),
Err(TryRecvError::Empty) => Ok(PollState::NotReady),
Err(TryRecvError::Disconnected) => {
Err(Error::trap("StdinPoll notify_rx channel closed"))
}
Err(TryRecvError::Disconnected) => Err(Error::trap(anyhow::Error::msg(
"StdinPoll notify_rx channel closed",
))),
},
}
}