From 9134635b372753cd94f0ed57f354ba9ffc2348e2 Mon Sep 17 00:00:00 2001 From: zach Date: Mon, 25 Nov 2024 08:49:57 -0800 Subject: [PATCH] cleanup: return better errors for wasi command modules (#793) --- runtime/src/plugin.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/runtime/src/plugin.rs b/runtime/src/plugin.rs index af22b13..8718c61 100644 --- a/runtime/src/plugin.rs +++ b/runtime/src/plugin.rs @@ -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.