mirror of
https://github.com/extism/extism.git
synced 2026-01-09 13:57:55 -05:00
cleanup: return better errors for wasi command modules (#793)
This commit is contained in:
@@ -906,8 +906,7 @@ impl Plugin {
|
||||
}
|
||||
|
||||
// on extism error
|
||||
if output_res.is_ok() && self.output.error_offset != 0 && self.output.error_length != 0
|
||||
{
|
||||
if output_res.is_ok() && self.extism_error_is_set() {
|
||||
let handle = MemoryHandle {
|
||||
offset: self.output.error_offset,
|
||||
length: self.output.error_length,
|
||||
@@ -927,7 +926,7 @@ impl Plugin {
|
||||
}
|
||||
Err(msg) => {
|
||||
res = Err(Error::msg(format!(
|
||||
"Call to Extism plugin function {name} encountered an error: {}",
|
||||
"unable to load error message from memory: {}",
|
||||
msg,
|
||||
)));
|
||||
}
|
||||
@@ -994,11 +993,12 @@ impl Plugin {
|
||||
plugin = self.id.to_string(),
|
||||
"WASI exit code: {}", exit_code
|
||||
);
|
||||
if exit_code == 0 {
|
||||
|
||||
if exit_code == 0 && !self.extism_error_is_set() {
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
return Err((e.context("WASI exit code"), exit_code));
|
||||
return Err((e, exit_code));
|
||||
}
|
||||
|
||||
// Handle timeout interrupts
|
||||
@@ -1026,6 +1026,10 @@ impl Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn extism_error_is_set(&self) -> bool {
|
||||
self.output.error_offset != 0 && self.output.error_length != 0
|
||||
}
|
||||
|
||||
/// Call a function by name with the given input, the return value is
|
||||
/// the output data returned by the plugin. The return type can be anything that implements
|
||||
/// [FromBytes]. This data will be invalidated next time the plugin is called.
|
||||
|
||||
Reference in New Issue
Block a user