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

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

Open
cs2dsb opened this issue May 31, 2024 · 1 comment · May be fixed by #488
Open

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

cs2dsb opened this issue May 31, 2024 · 1 comment · May be fixed by #488
Labels
bug Something isn't working

Comments

@cs2dsb
Copy link

cs2dsb commented May 31, 2024

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

@cs2dsb cs2dsb added the bug Something isn't working label May 31, 2024
@ranile ranile linked a pull request Jul 21, 2024 that will close this issue
@ranile
Copy link
Collaborator

ranile commented Jul 21, 2024

@cs2dsb apologies for the late response. #488 should resolve the issue you're havinb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants