wasm-tools-go icon indicating copy to clipboard operation
wasm-tools-go copied to clipboard

weird value printed when using function returning

Open rajatjindal opened this issue 1 month ago • 0 comments

Hello again,

I am trying to use wasm-tools-go to generate bindings for the following wit:

interface variables {
    /// Get an application variable value for the current component.
    ///
    /// The name must match one defined in in the component manifest.
    get: func(name: string) -> result<string, error>;

    /// The set of errors which may be raised by functions in this interface.
    variant error {
        /// The provided variable name is invalid.
        invalid-name(string),
        /// The provided variable is undefined.
        undefined(string),
        /// A variables provider specific error has occurred.
        provider(string),
        /// Some implementation-specific error has occurred.
        other(string),
    }
}

when using the bindings generated, I see weird value printed:

key: password, val is "\x00\x00\x00\x00\x00\x00"

pseudo code:

func Get(key string) (string, error) {
	result := variables.Get(key)
	if result.IsErr() {
		return "", errorVariantToError(*result.Err())
	}

	stdout.GetStdout().Write(cm.ToList([]byte(fmt.Sprintf("key: %s, val is %q \n", key, *result.OK()))))

	return *result.OK(), nil
}

I printed the value on host component implementation side, and it seems to be printing and returning the correct value.

any pointers what could be wrong here? thank you so much for all the help so far.

rajatjindal avatar May 19 '24 16:05 rajatjindal