extism / python-sdk

Extism Python Host SDK - easily run WebAssembly modules / plugins from Python applications
https://extism.org
BSD 3-Clause "New" or "Revised" License
19 stars 0 forks source link

memory issue getting error from extism #23

Closed nilslice closed 3 months ago

nilslice commented 3 months ago

I caught a stream at https://www.twitch.tv/ninja_tron where a bug was discovered... setError in the Zig PDK doesn't seem to get the correct output to Python SDK (at least in this case). It may also effect other SDKs, so we should test that.

I'm not sure if it is a bug in the Python SDK or the Zig PDK, so just opening it here to track and more easily create a repro.

The Python SDK did get some output when the error was written from the Zig PDK, but it was the wrong string from memory.

nilslice commented 3 months ago

tagging @zshipko to take a look 🙏

zshipko commented 3 months ago

interesting, it sounds similar to some of the other memory-related things i've been looking at - I will do some debugging tomorrow to try to figure this out!

nilslice commented 3 months ago

Thank you!

nilslice commented 3 months ago

Thanks to @zshipko's quick fix, this is resolved in the latest version -- please update your Python SDK to v1.0.2.

plugin.call will now raise using the error output from a plugin call to set the error message e.g.

SDK:

import extism

manifest = {"wasm": [{"path": "plugins/zig-example/zig-out/bin/zig-pdk-template.wasm"}]}
with extism.Plugin(manifest, wasi=True) as plugin:
    try:
      output = plugin.call(
          "run",
          "hello world",
      )
    except extism.Error as e:
      print("extism error caught:", e)

PDK:

const std = @import("std");
const extism_pdk = @import("extism-pdk");
const Plugin = extism_pdk.Plugin;

const allocator = std.heap.wasm_allocator;

export fn run() i32 {
    const plugin = Plugin.init(allocator);
    const name = plugin.getInput() catch unreachable;
    defer allocator.free(name);

    const output = std.fmt.allocPrint(allocator, "ERROR> Hello, {s}!", .{name}) catch unreachable;
    plugin.setError(output);
    return -1;
}
nilslice commented 3 months ago

(cc @ethanholz)