From fb3f48778b384bce0a1c8636726d9cbceb2fb640 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Thu, 25 Apr 2024 23:57:48 +0200 Subject: [PATCH] feat(wasix): More improvements to spawn error propagation --- lib/wasix/src/lib.rs | 6 +++--- lib/wasix/src/os/console/mod.rs | 4 +++- lib/wasix/src/syscalls/mod.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/wasix/src/lib.rs b/lib/wasix/src/lib.rs index 16441e41889..53c61cb5ed4 100644 --- a/lib/wasix/src/lib.rs +++ b/lib/wasix/src/lib.rs @@ -155,8 +155,8 @@ pub enum SpawnError { #[error("unsupported")] Unsupported, /// Not found - #[error("not found")] - NotFound, + #[error("not found: {message}")] + NotFound { message: String }, /// Tried to run the specified binary as a new WASI thread/process, but /// the binary name was not found. #[error("could not find binary '{binary}'")] @@ -240,7 +240,7 @@ impl SpawnError { /// [`NotFound`]: SpawnError::NotFound #[must_use] pub fn is_not_found(&self) -> bool { - matches!(self, Self::NotFound) + matches!(self, Self::NotFound { .. } | Self::MissingEntrypoint { .. }) } } diff --git a/lib/wasix/src/os/console/mod.rs b/lib/wasix/src/os/console/mod.rs index fda705314b1..67b1f167c1a 100644 --- a/lib/wasix/src/os/console/mod.rs +++ b/lib/wasix/src/os/console/mod.rs @@ -202,7 +202,9 @@ impl Console { .ok(); }); tracing::debug!(error=?e, %webc, "failed to get webc dependency"); - return Err(SpawnError::NotFound); + return Err(SpawnError::NotFound { + message: e.to_string(), + }); } }; diff --git a/lib/wasix/src/syscalls/mod.rs b/lib/wasix/src/syscalls/mod.rs index 0374b9d8b8a..2cd424ea9a0 100644 --- a/lib/wasix/src/syscalls/mod.rs +++ b/lib/wasix/src/syscalls/mod.rs @@ -1507,8 +1507,8 @@ pub(crate) fn _prepare_wasi(wasi_env: &mut WasiEnv, args: Option>) { pub(crate) fn conv_spawn_err_to_errno(err: &SpawnError) -> Errno { match err { SpawnError::AccessDenied => Errno::Access, - SpawnError::NotFound => Errno::Noent, SpawnError::Unsupported => Errno::Noexec, + _ if err.is_not_found() => Errno::Noent, _ => Errno::Inval, } }