Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate serde error message to JS exception #19

Merged

Conversation

steos
Copy link
Contributor

@steos steos commented Apr 27, 2023

When deserializing a tsified struct from a JS value the serde error message gets lost. With this change the error message gets propagated as the JS exception message.

Consider this example:

#[derive(Debug, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct Foo {
    foo: String
}

#[wasm_bindgen]
pub fn foobar(params: Foo) -> Result<String, JsError> {
    Ok(String::from("hello"))
}

When calling foobar from JS with invalid Foo

before:

foobar()
// Uncaught Error: `unwrap_throw` failed

foobar({})
// Uncaught Error: `unwrap_throw` failed
 

after:

foobar()
// Uncaught Error: Error: invalid type: unit value, expected struct Foo

foobar({})
// Uncaught Error: Error: missing field `foo`

@madonoharu
Copy link
Owner

Sorry for the late reply.
Thank you!

@madonoharu madonoharu merged commit bc4cfa1 into madonoharu:main May 24, 2023
@nikgraf nikgraf deleted the throw-with-serde-error-message branch May 30, 2023 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants