Skip to content

Trapped on unreachable instruction in a go-pdk example #49

@sap1ens

Description

@sap1ens

This could be more relevant for https://github.com/dylibso/chicory, but creating an issue here to start.

I want to run a JSON example from the go-pdk. I can compile the example with tinygo and run it with the extism CLI:

extism call plugin.wasm add --input='{"a": 20, "b": 21}' --wasi
{"sum":41}

However, I'm getting com.dylibso.chicory.runtime.TrapException: Trapped on unreachable instruction when trying to run it with chicory-sdk. Debugging the interpreter steps shows me that it goes to panic directly from the exported function, but it's not clear why.

Here's the minimal test to reproduce:

package org.extism.sdk.chicory;

import com.dylibso.chicory.wasi.WasiOptions;
import junit.framework.TestCase;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class GolangTest extends TestCase {
    public void testJson() throws IOException {
        var wasm = ManifestWasm.fromBytes(this.getClass().getResourceAsStream("/add.wasm").readAllBytes()).build();
        var manifest = Manifest.ofWasms(wasm).withOptions(new Manifest.Options().withWasi(WasiOptions.builder().build())).build();

        var plugin = Plugin.ofManifest(manifest).build();

        var input = "{\"a\": 20, \"b\": 21}";
        var result = new String(plugin.call("add", input.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);

        System.out.println(result);
    }
}

add.wasm was compiled from the go-pdk JSON example like this:

tinygo build -o add.wasm -target wasip1 -buildmode=c-shared main.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions