Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/wasi/src/preview2/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ wasmtime::component::bindgen!({
async: true,
trappable_error_type: {
"wasi:filesystem/types"::"error-code": Error,
"wasi:io/streams"::"stream-error": Error,
},
with: {
"wasi:filesystem/types": crate::preview2::bindings::filesystem::types,
Expand Down Expand Up @@ -61,7 +60,6 @@ pub mod sync {
async: false,
trappable_error_type: {
"wasi:filesystem/types"::"error-code": Error,
"wasi:io/streams"::"stream-error": Error,
},
with: {
"wasi:filesystem/types": crate::preview2::bindings::sync_io::filesystem::types,
Expand Down
14 changes: 5 additions & 9 deletions crates/wasi/src/preview2/filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::preview2::{StreamState, Table, TableError};
use crate::preview2::{StreamRuntimeError, StreamState, Table, TableError};
use bytes::{Bytes, BytesMut};
use std::sync::Arc;

Expand Down Expand Up @@ -152,24 +152,20 @@ impl FileInputStream {
}
}

pub(crate) fn read_result(
r: Result<usize, std::io::Error>,
) -> Result<(usize, StreamState), std::io::Error> {
fn read_result(r: Result<usize, std::io::Error>) -> Result<(usize, StreamState), anyhow::Error> {
match r {
Ok(0) => Ok((0, StreamState::Closed)),
Ok(n) => Ok((n, StreamState::Open)),
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => Ok((0, StreamState::Open)),
Err(e) => Err(e),
Err(e) => Err(StreamRuntimeError::from(anyhow::anyhow!(e)).into()),
}
}

pub(crate) fn write_result(
r: Result<usize, std::io::Error>,
) -> Result<(usize, StreamState), std::io::Error> {
fn write_result(r: Result<usize, std::io::Error>) -> Result<(usize, StreamState), anyhow::Error> {
match r {
Ok(0) => Ok((0, StreamState::Closed)),
Ok(n) => Ok((n, StreamState::Open)),
Err(e) => Err(e),
Err(e) => Err(StreamRuntimeError::from(anyhow::anyhow!(e)).into()),
}
}

Expand Down
7 changes: 5 additions & 2 deletions crates/wasi/src/preview2/host/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,18 @@ impl<T: WasiView> types::Host for T {
})
.await;

let (bytes_read, state) = crate::preview2::filesystem::read_result(r)?;
let (bytes_read, state) = match r? {
0 => (0, true),
n => (n, false),
};

buffer.truncate(
bytes_read
.try_into()
.expect("bytes read into memory as u64 fits in usize"),
);

Ok((buffer, state.is_closed()))
Ok((buffer, state))
}

async fn write(
Expand Down
Loading