diff --git a/Cargo.toml b/Cargo.toml index 109ea80..5d2419b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,10 +51,10 @@ tempfile = "3.3.0" tokio = { version = "1.21.2", default-features = false } uuid = "1.1.2" wash = { version = "0.1.0", git = "https://github.com/rvolosatovs/wash", artifact = "bin", target = "wasm32-wasi", default-features = false } -wasi-common = "2.0.0" -wasmtime = "2.0.0" +wasi-common = "3.0.1" +wasmtime = "3.0.1" wasmtime-vfs-dir = { path = "./dir", version = "0.1.0" } wasmtime-vfs-file = { path = "./file", version = "0.1.0" } wasmtime-vfs-ledger = { path = "./ledger", version = "0.1.0" } wasmtime-vfs-memory = { path = "./memory", version = "0.1.0" } -wasmtime-wasi = "2.0.0" +wasmtime-wasi = "3.0.1" diff --git a/file/src/lib.rs b/file/src/lib.rs index c53266c..517ee68 100644 --- a/file/src/lib.rs +++ b/file/src/lib.rs @@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut}; use std::sync::Arc; use wasi_common::file::{Advice, FdFlags, FileType, Filestat}; -use wasi_common::{Error, ErrorExt, ErrorKind, SystemTimeSpec, WasiDir, WasiFile}; +use wasi_common::{Error, ErrorExt, SystemTimeSpec, WasiDir, WasiFile}; use wasmtime_vfs_ledger::InodeId; use wasmtime_vfs_memory::{Data, Inode, Link, Node, Open, State}; @@ -295,16 +295,17 @@ impl WasiFile for OpenFile { SeekFrom::Current(_) => i64::try_from(olock.pos), SeekFrom::Start(_) => Ok(0), SeekFrom::End(_) => i64::try_from(ilock.content.len()), - }; + } + .map_err(|e| Error::invalid_argument().context(e))?; let off = match pos { SeekFrom::Current(off) => Ok(off), SeekFrom::Start(off) => i64::try_from(off), SeekFrom::End(off) => Ok(off), - }; + } + .map_err(|e| Error::invalid_argument().context(e))?; - let pos = cur.map_err(|_| ErrorKind::Inval)? + off.map_err(|_| ErrorKind::Inval)?; - let pos = usize::try_from(pos).map_err(|_| ErrorKind::Inval)?; + let pos = usize::try_from(cur + off).map_err(|e| Error::invalid_argument().context(e))?; olock.pos = pos; Ok(pos as u64) diff --git a/keyfs/src/generate.rs b/keyfs/src/generate.rs index 8b1aaf3..f28817b 100644 --- a/keyfs/src/generate.rs +++ b/keyfs/src/generate.rs @@ -373,7 +373,7 @@ impl WasiFile for OpenGenerate { return Ok(total as u64); } - Err(ErrorKind::WouldBlk.into()) + Err(std::io::Error::from(std::io::ErrorKind::WouldBlock).into()) } async fn write_vectored<'a>(&mut self, bufs: &[IoSlice<'a>]) -> Result { diff --git a/keyfs/src/trust.rs b/keyfs/src/trust.rs index fc0c739..89b096c 100644 --- a/keyfs/src/trust.rs +++ b/keyfs/src/trust.rs @@ -278,7 +278,7 @@ impl WasiFile for OpenTrust { return Ok(total as u64); } - Err(ErrorKind::WouldBlk.into()) + Err(std::io::Error::from(std::io::ErrorKind::WouldBlock).into()) } async fn write_vectored<'a>(&mut self, bufs: &[IoSlice<'a>]) -> Result { diff --git a/tests/util/wash.rs b/tests/util/wash.rs index e87302c..d8c011a 100644 --- a/tests/util/wash.rs +++ b/tests/util/wash.rs @@ -2,8 +2,8 @@ use super::{Noop, Surround, Tee}; use anyhow::{bail, Context}; use wasi_common::pipe::{ReadPipe, WritePipe}; -use wasi_common::{WasiDir, WasiFile}; -use wasmtime::{Engine, Linker, Module, Store, Trap}; +use wasi_common::{I32Exit, WasiDir, WasiFile}; +use wasmtime::{Engine, Linker, Module, Store}; use wasmtime_wasi::{stdio, WasiCtxBuilder}; pub async fn wash( @@ -80,8 +80,7 @@ pub async fn wash( .typed::<(), (), _>(&store) .context("failed to assert default function type")? .call(&mut store, ()) - .as_ref() - .map_err(Trap::i32_exit_status) + .map_err(|e| e.downcast().map(|I32Exit(code)| code)) .expect_err("`wash` did not set an exit code, did you forget to execute `exit`?") .context("failed to execute default function")? };