Skip to content

[docs] rust frontend crash when a command returns an error with current examples #3457

@dzamlo

Description

@dzamlo

With the current examples, when invoking a command that return an error (a Err variant of a Result type) from a rust frontend, the rust frontend panic with an error about "unexpected exception".

The solution I found is to adjust the wasm_bindgen definition to the following:

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(catch, js_namespace = ["window", "__TAURI__", "core"])]
    async fn invoke(cmd: &str, args: JsValue) -> Result<JsValue, JsValue>;
}

And adjust the code using invoke to handle the result.

Maybe a better idea is to define two invoke external functions, one with the catch and one without, I don't know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🪵 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions