golem icon indicating copy to clipboard operation
golem copied to clipboard

Cannot call static resource methods from TypeScript

Open vigoo opened this issue 1 year ago • 2 comments

Take the following example:

import {Bucket, OutgoingValue} from "wasi:keyvalue/[email protected]";

function unwrap<T, E>(result: Result<T, E>): T {
    if (result.tag === 'ok') {
        return result.val;
    } else {
        throw new Error(`Error: ${result.val}`);
    }
}

// ...

const deadlinesBucket = unwrap(Bucket.openBucket("deadlines"));

trying to call this WIT static resource method:

	resource bucket {
		/// Opens a bucket with the given name.
		/// 
		/// If any error occurs, including if the bucket does not exist, it returns an `Err(error)`.
		open-bucket: static func(name: string) -> result<bucket, error>;
  	}

This fails in componentizewith:

thread '<unnamed>' panicked at crates/spidermonkey-embedding-splicer/src/bindgen.rs:737:51:
no entry found for key
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
(jco componentize) RuntimeError: unreachable
    at spidermonkey_embedding_splicer.wasm.__rust_start_panic (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6700]:0x392a8c)
    at spidermonkey_embedding_splicer.wasm.rust_panic (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6692]:0x3925b1)
    at spidermonkey_embedding_splicer.wasm._ZN3std9panicking20rust_panic_with_hook17h50e657195af0239cE (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6691]:0x392367)
    at spidermonkey_embedding_splicer.wasm._ZN3std9panicking19begin_panic_handler28_$u7b$$u7b$closure$u7d$$u7d$17h0187e6969a85aab0E (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6679]:0x391789)
    at spidermonkey_embedding_splicer.wasm._ZN3std10sys_common9backtrace26__rust_end_short_backtrace17h575fb82445d56667E (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6678]:0x3916f0)
    at spidermonkey_embedding_splicer.wasm.rust_begin_unwind (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6686]:0x391eff)
    at spidermonkey_embedding_splicer.wasm._ZN4core9panicking9panic_fmt17ha6764f2272b7fb95E (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6839]:0x3a0693)
    at spidermonkey_embedding_splicer.wasm._ZN4core6option13expect_failed17h4bbb25fdd9d02fc5E (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[6893]:0x3a8363)
    at spidermonkey_embedding_splicer.wasm._ZN30spidermonkey_embedding_splicer7bindgen9JsBindgen14iter_resources17heba57e83495056d8E (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[51]:0x15f59)
    at spidermonkey_embedding_splicer.wasm._ZN30spidermonkey_embedding_splicer7bindgen9JsBindgen7bindgen17hba69385eb49a1937E (wasm://wasm/spidermonkey_embedding_splicer.wasm-012ed902:wasm-function[50]:0x15449)

vigoo avatar Aug 20 '24 16:08 vigoo

Fixed upstream: https://github.com/bytecodealliance/ComponentizeJS/issues/126

vigoo avatar Aug 26 '24 05:08 vigoo

updated our starling / componentize / jco forks with the recent changes, componentize do not fail now, but using Bucket.openBucket returns an empty js object (with no val or tag fields), so that will need more investigation

noise64 avatar Aug 26 '24 12:08 noise64

I think this is fixed by https://github.com/golemcloud/jco/pull/9

vigoo avatar Mar 21 '25 08:03 vigoo