{"record":{"id":"fa73cc138f65e7bd","repo":"gfx-rs/wgpu","slug":"unexpected-error-constructor-constructor-value","errorCode":null,"errorMessage":"Unexpected error: constructor={constructor} value={value}","messagePattern":"Unexpected error: constructor=(.+?) value=(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu/src/backend/webgpu.rs","lineNumber":95,"sourceCode":"        crate::Error::Validation {\n            source,\n            description: js_error.message(),\n        }\n    } else if let Some(js_error) = js_error.dyn_ref::<webgpu_sys::GpuInternalError>() {\n        crate::Error::Internal {\n            source,\n            description: js_error.message(),\n        }\n    } else if js_error.has_type::<webgpu_sys::GpuOutOfMemoryError>() {\n        crate::Error::OutOfMemory { source }\n    } else {\n        let constructor = js_error\n            .constructor()\n            .name()\n            .as_string()\n            .unwrap_or_default();\n        let value = js_error.to_string().as_string().unwrap_or_default();\n        panic!(\"Unexpected error: constructor={constructor} value={value}\");\n    }\n}\n\n/// A callback invoked when wgpu releases its reference to an externally\n/// owned WebGPU resource (e.g. a `GpuTexture` passed to\n/// [`crate::Device::create_texture_from_webgpu_handle`]).\n///\n/// This is the WebGPU counterpart of [`wgpu_hal::DropCallback`].\npub type DropCallback = Box<dyn FnOnce() + 'static>;\n\npub(crate) struct DropGuard {\n    callback: Option<DropCallback>,\n}\n\nimpl DropGuard {\n    fn new(callback: Option<DropCallback>) -> Self {\n        Self { callback }\n    }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu/src/backend/webgpu.rs#L77-L113","documentation":"In the WebGPU (browser) backend, error_from_js converts a JavaScript exception into a Rust error; if the JS value is not one of the recognized WebGPU error DOMException types, it panics with the constructor name and stringified value. It is reached from future_pop_error_scope and on_uncaptured_error when the browser surfaces an unexpected exception.","triggerScenarios":"An uncaptured JS error or popped error scope containing a non-WebGPU exception (e.g. TypeError, RangeError, or an arbitrary thrown value) instead of a GPUValidationError/GPUOutOfMemoryError/GPUInternalError.","commonSituations":"Browser bugs or vendor extensions surfacing non-standard exceptions; passing invalid JS objects into WebGPU; device-lost / context-loss paths in some browsers; mismatched web-sys versions exposing unknown error constructors.","solutions":["Inspect the printed constructor= and value= to identify the underlying JS exception and fix the call that caused it.","Capture errors with device.push_error_scope/pop_error_scope and on_uncaptured_error handlers so failures are handled before reaching this path.","Update wgpu and the browser to compatible versions if the exception comes from a browser-specific quirk."],"exampleFix":"// before\n// no handler: JS exception becomes a panic\n// after\ndevice.on_uncaptured_error(Box::new(|err| {\n    log::error!(\"wgpu error: {err}\");\n}));","handlingStrategy":"try-catch","validationCode":"device.push_error_scope(wgpu::ErrorFilter::Validation);\n// ... GPU work ...\nlet err = device.pop_error_scope().await;","typeGuard":null,"tryCatchPattern":"// in on_uncaptured_error / pop_error_scope, log and recover instead of letting the JS exception propagate:\ndevice.on_uncaptured_error(Box::new(|err| log::error!(\"wgpu: {err}\")));","preventionTips":["Always install an on_uncaptured_error handler on the device.","Wrap per-frame GPU work in push_error_scope/pop_error_scope.","Keep wgpu, web-sys, and browser versions up to date; note the constructor= value in bug reports."],"tags":["panic","rust","webgpu","browser","unexpected-exception"],"backgroundTag":"unexpected-js-exception","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}