Skip to content

TryFrom<JsValue> for JsError panics in the NotJsError case if the JsValue isn't a string #477

Open
@cs2dsb

Description

@cs2dsb

Describe the Bug

The library I'm calling (sqlite3.js) returns an object with "type": "Error" instead of an instance of Error or a String. Calling try_from panics because the fallback case calls JsString::from which panics if the type is wrong. It should probably call try_from and fallback to calling fmt::Debug or similar in the non-string case. I can work around it but the try_from panicking seems unexpected.

Here is the relevant line:

let js_to_string = String::from(js_sys::JsString::from(js_value.clone()));

Steps to Reproduce

Reject a promise with an object and call JsError::try_from on the resulting JsValue.

Expected Behavior

I don't think try_from should ever panic. Making the string on NotJsError optional or making the error type an enum would make more sense to me.

Actual Behavior

Panics in JsString::from with "unwrap_throw failed".

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions