StarlingMonkey icon indicating copy to clipboard operation
StarlingMonkey copied to clipboard

Error when sending `POST` requests with `fetch`

Open karthik2804 opened this issue 4 months ago • 1 comments

When trying to run the following code

addEventListener('fetch', (event) => handleRequest(event));
async function handleRequest(event) {
    try {
        let res = await fetch("https://echo.free.beeceptor.com", {
            method: "POST",
            headers: {},
            body: "hello world"
        }).then(data => data.text()).then(data => console.log(data))
        event.respondWith(new Response("Hello world"));
    } catch (e) {
        console.log(`Error: ${e}\nStack: ${e.stack}`);
    }
}

I get the following error

2024-03-01T15:29:59.022310Z ERROR spin_trigger_http: Error processing request: guest invocation failed

Caused by:
    0: error while executing at wasm backtrace:
           0: 0xa70d4b2 - wit-component:shim!indirect-wasi:http/[email protected][method]fields.append
           1: 0x3ca28 - <unknown>!wasi_http_types_method_fields_append
           2: 0x23c78 - <unknown>!host_api::HttpHeaders::append(std::__2::basic_string_view<char, std::__2::char_traits<char>>, std::__2::basic_string_view<char, std::__2::char_traits<char>>)
           3: 0xc59f2 - <unknown>!builtins::web::fetch::Headers::append_header_value(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<JS::Value>, char const*)
           4: 0xcdad1 - <unknown>!builtins::web::fetch::Headers::maybe_add(JSContext*, JS::Handle<JSObject*>, char const*, char const*)
           5: 0xd65fb - <unknown>!builtins::web::fetch::RequestOrResponse::extract_body(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>)
           6: 0xe4fb2 - <unknown>!builtins::web::fetch::Request::create(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::Handle<JS::Value>)
           7: 0xc2f78 - <unknown>!builtins::web::fetch::fetch(JSContext*, unsigned int, JS::Value*)
           8: 0x6a3fcf - <unknown>!js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason)
           9: 0x69e029 - <unknown>!js::Interpret(JSContext*, js::RunState&)
          10: 0x696478 - <unknown>!js::RunScript(JSContext*, js::RunState&)
          11: 0x6a3e0b - <unknown>!js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason)
          12: 0x6a4ae0 - <unknown>!js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason)
          13: 0x733872 - <unknown>!JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>)
          14: 0xf4add - <unknown>!builtins::web::fetch::fetch_event::dispatch_fetch_event(JS::Handle<JSObject*>, double*)
          15: 0xf43ed - <unknown>!exports_wasi_http_incoming_handler_handle
          16: 0x47f27 - <unknown>!__wasm_export_exports_wasi_http_incoming_handler_handle
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    1: unknown handle index 0    

karthik2804 avatar Mar 01 '24 15:03 karthik2804