You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to have function that accepts a JsValue argument and checked at run-time which of several #[wasm_bindgen] structs it was and does something slightly different for each one. I instead got a hard to diagnose panic in a different crate caused by ::js_sys::Reflect::set returning a leftover error.
Steps to Reproduce
The code I wrote looked like this:
ifletOk(x) = FirstStruct::try_from_js_value(value.clone()){
...}elseifletOk(mesh) = SecondStruct::try_from_js_value(value.clone()){
...}else{returnErr(JsError::new("should be FirstStruct or SecondStruct"))}
Shortly after this I made some wgpu calls, and one of them panicked out of nowhere on an assertion that said "setting properties should never fail".
Changing the order of the types checked fixed the problem, until I tried the other type.
Expected Behavior
Any error set by try_from_js_value should be contained in its return value, and not be able to affect other code. I should not be required to return an error when try_from_js_value fails; checking multiple types should be a valid.
Alternatively, this pattern should be prevented by the compiler somehow, or worst case documented as causing problems.
Tim-Evans-Seequent
changed the title
Delayed error using a chain of try_from_js_value on a #[wasm_bindgen] structs
Delayed error using a chain of try_from_js_value on #[wasm_bindgen] structs
Nov 27, 2024
Describe the Bug
I wanted to have function that accepts a
JsValue
argument and checked at run-time which of several #[wasm_bindgen] structs it was and does something slightly different for each one. I instead got a hard to diagnose panic in a different crate caused by::js_sys::Reflect::set
returning a leftover error.Steps to Reproduce
The code I wrote looked like this:
Shortly after this I made some
wgpu
calls, and one of them panicked out of nowhere on an assertion that said "setting properties should never fail".Changing the order of the types checked fixed the problem, until I tried the other type.
Expected Behavior
Any error set by
try_from_js_value
should be contained in its return value, and not be able to affect other code. I should not be required to return an error whentry_from_js_value
fails; checking multiple types should be a valid.Alternatively, this pattern should be prevented by the compiler somehow, or worst case documented as causing problems.
Actual Behavior
A subsequent call to
js_sys::Reflect::set
insidewgpu::backend::webgpu::webgpu_sys::gen_GpuBufferDescriptor::GpuBufferDescriptor::size
failed and caused a panic. This assertion is debug only, in release mode I instead got an error from WebGPU due to the missing field.This was running on Chrome on Windows in case that matters.
The text was updated successfully, but these errors were encountered: