Skip to content

Commit

Permalink
chore(wasix): Cleanup of various review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed Jun 22, 2023
1 parent 96bed05 commit 3cc1331
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 36 deletions.
1 change: 1 addition & 0 deletions lib/wasix/src/bin_factory/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub async fn spawn_exec(
error = &*err,
"Failed to compile the module",
);
env.cleanup(Some(Errno::Noexec.into())).await;
return Err(SpawnError::CompileError);
}
};
Expand Down
29 changes: 1 addition & 28 deletions lib/wasix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub enum SpawnError {
UnknownError,
#[error("runtime error")]
Runtime(#[from] WasiRuntimeError),
#[error("{0}")]
#[error(transparent)]
Other(#[from] Box<dyn std::error::Error + Send + Sync>),
}

Expand Down Expand Up @@ -222,33 +222,6 @@ impl WasiRuntimeError {
}
}

/// Wrapper for [`anyhow::Error`] that implements [`std::error::Error`].
pub struct AnyhowStdError(pub anyhow::Error);

impl std::fmt::Debug for AnyhowStdError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl std::fmt::Display for AnyhowStdError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl std::error::Error for AnyhowStdError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&*self.0)
}
}

impl From<anyhow::Error> for AnyhowStdError {
fn from(error: anyhow::Error) -> Self {
Self(error)
}
}

#[allow(clippy::result_large_err)]
pub(crate) fn run_wasi_func(
func: &wasmer::Function,
Expand Down
10 changes: 2 additions & 8 deletions lib/wasix/src/os/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,27 +218,21 @@ impl Console {
.with_capabilities(self.capabilities.clone())
.prepare_webc_env(prog, &wasi_opts, &pkg, self.runtime.clone(), Some(root_fs))
// TODO: better error conversion
.map_err(|err| SpawnError::Other(Box::new(crate::AnyhowStdError(err))))?;
.map_err(|err| SpawnError::Other(err.into()))?;

// TODO: no unwrap!
let env = builder
.stdin(Box::new(self.stdin.clone()))
.stdout(Box::new(self.stdout.clone()))
.stderr(Box::new(self.stderr.clone()))
.build()?;

// TODO: this should not happen here...
// Display the welcome message
if !self.whitelabel && !self.no_welcome {
tasks.block_on(self.draw_welcome());
}

let wasi_process = env.process.clone();

// TODO: fetching dependencies should be moved to the builder!
// TODO: the Console only makes sense in the context of SSH and the terminal.
// We should make this just take a WasiBuilder and the console related configs
// and not add so much custom logic in here.
if let Err(err) = env.uses(self.uses.clone()) {
let mut stderr = self.stderr.clone();
tasks.block_on(async {
Expand Down Expand Up @@ -281,7 +275,7 @@ impl Console {
}
}

#[cfg(test, not(target_family = "wasm"))]
#[cfg(all(test, not(target_family = "wasm")))]
mod tests {
use virtual_fs::{AsyncSeekExt, BufferFile, Pipe};

Expand Down

0 comments on commit 3cc1331

Please sign in to comment.