Skip to content

Commit

Permalink
Merge pull request #522 from fabriziosestito/fix/fix-wasi-runtime-rej…
Browse files Browse the repository at this point in the history
…ection-response

fix: WASI runtime rejection response
  • Loading branch information
fabriziosestito authored Jun 17, 2024
2 parents 64b37a9 + 4a83de7 commit 8bc7ac1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/runtimes/wasi_cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ pub type Result<T> = std::result::Result<T, WasiRuntimeError>;

#[derive(Error, Debug)]
pub enum WasiRuntimeError {
#[error("program exited with code {code:?}; stderr set to '{stderr}', error: '{error}'")]
#[error("{stderr}")]
WasiEvaluation {
code: Option<i32>,
stderr: String,
#[source]
error: wasmtime::Error,
Expand Down
5 changes: 1 addition & 4 deletions src/runtimes/wasi_cli/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ impl<'a> Runtime<'a> {
),
}
}
Err(e) => AdmissionResponse::reject_internal_server_error(
request.uid().to_string(),
e.to_string(),
),
Err(e) => AdmissionResponse::reject(request.uid().to_string(), e.to_string(), 500),
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/runtimes/wasi_cli/stack.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::io::Cursor;
use std::sync::{Arc, RwLock};
use tracing::debug;
use wasi_common::pipe::{ReadPipe, WritePipe};
use wasi_common::sync::WasiCtxBuilder;
use wasi_common::WasiCtx;
Expand Down Expand Up @@ -71,26 +72,25 @@ impl Stack {
// references to the WritePipe(s) that we need exclusive access to.
drop(store);

let stderr = pipe_to_string("stderr", stderr_pipe)?;
let stderr = pipe_to_string("stderr", stderr_pipe)?.trim().to_string();

if let Err(err) = evaluation_result {
if let Some(exit_error) = err.downcast_ref::<wasi_common::I32Exit>() {
if exit_error.0 == EXIT_SUCCESS {
let stdout = pipe_to_string("stdout", stdout_pipe)?;
return Ok(RunResult { stdout, stderr });
} else {
return Err(WasiRuntimeError::WasiEvaluation {
code: Some(exit_error.0),
stderr,
error: err,
});
debug!(
"WASI program exited with error code: {}, error: {}",
exit_error.0, stderr
);

return Err(WasiRuntimeError::WasiEvaluation { stderr, error: err });
}
}
return Err(WasiRuntimeError::WasiEvaluation {
code: None,
stderr,
error: err,
});

debug!("WASI program exited with error: {}", stderr);
return Err(WasiRuntimeError::WasiEvaluation { stderr, error: err });
}

let stdout = pipe_to_string("stdout", stdout_pipe)?;
Expand Down

0 comments on commit 8bc7ac1

Please sign in to comment.