Skip to content

fix: return an error for any non-zero exit code #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/org/extism/sdk/LibExtism.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Pointer extism_function_new(String name,
* @param nFunctions the number of host functions
* @param withWASI enables/disables WASI
* @param errmsg get the error message if the return value is null
* @return id of the plugin or {@literal -1} in case of error
* @return pointer to the plugin, or null in case of error
*/
Pointer extism_plugin_new(byte[] wasm, long wasmSize, Pointer[] functions, int nFunctions, boolean withWASI, Pointer[] errmsg);

Expand All @@ -138,7 +138,7 @@ Pointer extism_function_new(String name,
* @param function_name is the function to call
* @param data is the data input data
* @param dataLength is the data input data length
* @return the result code of the plugin call. {@literal -1} in case of error, {@literal 0} otherwise.
* @return the result code of the plugin call. non-zero in case of error, {@literal 0} otherwise.
*/
int extism_plugin_call(Pointer pluginPointer, String function_name, byte[] data, int dataLength);

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/extism/sdk/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public byte[] call(String functionName, byte[] inputData) {

int inputDataLength = inputData == null ? 0 : inputData.length;
int exitCode = LibExtism.INSTANCE.extism_plugin_call(this.pluginPointer, functionName, inputData, inputDataLength);
if (exitCode == -1) {
if (exitCode != 0) {
String error = this.error();
throw new ExtismException(error);
}
Expand Down Expand Up @@ -114,7 +114,11 @@ public String call(String functionName, String input) {
* @return the error message
*/
protected String error() {
return LibExtism.INSTANCE.extism_plugin_error(this.pluginPointer);
String error = LibExtism.INSTANCE.extism_plugin_error(this.pluginPointer);
if (error == null){
return new String("Unknown error encountered when running Extism plugin function");
}
return error;
}

/**
Expand Down