Closed ritesh089 closed 4 days ago
Hi @ritesh089 could you share the world you're targeting?
Typically wasi:http/outgoing-handler
is imported by components, whereas wasi:http/incoming-handler
is typically exported by components.
`package wasmcloud:hello;
world hello { include wasmcloud:component/imports; import wasi:http/outgoing-handler@0.2.0; export wasi:http/incoming-handler@0.2.0; } `
Thanks!
This is surprising - could you share the reproduction steps? And could you confirm that wasmcloud:component/imports
is defined as https://github.com/wasmCloud/component-sdk-go/blob/13ee4681784f10ecc589fc471a5e681c72290b9e/wit/world.wit#L11-L25 (check in your wit/deps
directory)
Going to do a little guess here, any chance you are attempting to use west
to test the component? The included test harness uses WASI 0.2.1, so the fix would be to use wasi:http/outgoing-handler@0.2.1
Yes I am using the same world. Even without the http client this is failing with the same error . My wit :
package wasmcloud:hello;
world hello {
include wasmcloud:component/imports;
export wasi:http/incoming-handler@0.2.0;
}
Code :
package main
import (
"net/http"
"go.wasmcloud.dev/component/log/wasilog"
"go.wasmcloud.dev/component/net/wasihttp"
)
//go:generate wit-bindgen-go generate --world example --out gen ./wit
// Helper type aliases to make code more readable
type HttpServer struct{}
func init() {
// We can't use http.ServeMux yet ( only symbol linking is supported in 'init' )
wasihttp.HandleFunc(handle)
}
func handle(w http.ResponseWriter, r *http.Request) {
logger := wasilog.ContextLogger("postHandler")
mockResponse := "Hello, World from wasex!"
logger.Info("Handling request", "method", r.Method, "url", r.URL)
w.Write([]byte("Response: " + mockResponse))
}
//go:generate wit-bindgen tiny-go wit --out-dir=gen --gofmt
func main() {}
Steps : wash build (success)
wash app deploy wadm.yaml
Error :
DEBUG handle_scale_component_task:start_component: wasmcloud_host::wasmbus: starting new component component_ref="file:///Users/rrai35/git/wasm/wasmcloud/examples/go-test/build/http_hello_world_s.wasm" max_instances=1
2024-09-24T15:12:55.577372Z DEBUG process_claims_put: wasmcloud_host::wasmbus: process claim entry put pubkey="MCH2QSPGKF37K7M5SEJMHITF336ZKG5DU63H4F6N24S4Y4KLT3FMYNA2"
2024-09-24T15:12:55.585054Z ERROR wasmcloud_host::wasmbus: failed to scale component component_ref=file:///Users/rrai35/git/wasm/wasmcloud/examples/go-test/build/http_hello_world_s.wasm component_id=tinygo_hello_world-http_component err=failed to encode a component from module
Caused by:
0: failed to decode world from module
1: module was not valid
2: failed to validate exported interface `wasi:http/outgoing-handler@0.2.0`
3: module does not export required function `wasi:http/outgoing-handler@0.2.0#handle`
Wadm:
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: tinygo-hello-world
annotations:
description: 'HTTP hello world demo in Golang (TinyGo), using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)'
wasmcloud.dev/authors: wasmCloud team
wasmcloud.dev/source-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/wadm.yaml
wasmcloud.dev/readme-md-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/README.md
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
wasmcloud.dev/categories: |
http,outgoing-http,http-server,tinygo,golang,example
spec:
components:
- name: http-component
type: component
properties:
image: file://./build/http_hello_world_s.wasm
traits:
# Govern the spread/scheduling of the component
- type: spreadscaler
properties:
instances: 1
# Add a capability provider that enables HTTP access
- name: httpserver
type: capability
properties:
image: ghcr-io-proxy/ghcr.io/wasmcloud/http-server:0.22.0
traits:
# Link the httpserver to the component, and configure the HTTP server
# to listen on port 8080 for incoming requests
#
# Since the HTTP server calls the `http-component` component, we establish
# a unidirectional link from this `httpserver` provider (the "source")
# to the `http-component` component (the "target"), so the server can invoke
# the component to handle a request.
- type: link
properties:
target: http-component
namespace: wasi
package: http
interfaces: [incoming-handler]
source_config:
- name: default-http
properties:
address: 127.0.0.1:8080
I'm iterating on outgoing-handler
in #7
Hey @ritesh089, I notice that in your wit-bindgen-go generate
call you use --world example
, whereas in the WIT you shared, the world is called hello
.
Any chance there could be a mismatch here? Perhaps the issue is that the bindings are stale? (could you try to delete the generated code and regenerate it targeting the hello
world?)
Additionally, I believe you should not need to generate bindings at all using this SDK
I updated the generate with 'hello' . Now there is no gen directory. I still get the same error .
Hi @ritesh089 , can you share your wasmcloud.toml
please?
@lxfontes Here is my toml :
name = "http-hello-world"
language = "tinygo"
type = "component"
version = "0.1.0"
[component]
build_command = "tinygo build -target=wasip2 --wit-package ./wit --wit-world hello -o build/hello.wasm hello.go"
wit_world = "hello"
wasm_target = "wasm32-wasi-preview2"
destination = "build/http_hello_world_s.wasm"
@ritesh089 think this is due to the language.
Set it to:
language = "other"
This is needed until https://github.com/wasmCloud/wasmCloud/issues/3049 lands later this week.
Same error .
When i add http client code and build, i get compilation error as well.
When I do that, wash build fails :
wash build
failed to build component with custom command: "error: failed to encode a component from module\n\nCaused by:\n 0: failed to decode world from module\n 1: module was not valid\n 2: module requires an import interface named `wasi:http/outgoing-handler@0.2.0`\nwasm-tools failed: exit status 1\n"
paired with Ritesh and sorted this out ( was a path / cached binary error )
When i try to make a http client call , i get the error :
error: failed to encode a component from module\n\nCaused by:\n 0: failed to decode world from module\n 1: module was not valid\n 2: failed to validate exported interface
wasi:http/outgoing-handler@0.2.0
\n 3: module does not export required function `wasi:http/outgoing-handler@0.2.0#handlWhen i see the wit for component-sdk-go , I only see the incoming handler there . outgoinghandler for http was missing.