{"record":{"id":"c1099b7ea7215229","repo":"gfx-rs/wgpu","slug":"name-is-not-webgpu","errorCode":null,"errorMessage":"${name} is not webgpu","messagePattern":"(.+?) is not webgpu","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu/src/dispatch.rs","lineNumber":852,"sourceCode":"            }\n\n            #[cfg(custom)]\n            #[inline]\n            #[allow(clippy::allow_attributes, unused)]\n            pub fn as_custom<T: $interface>(&self) -> Option<&T> {\n                match self {\n                    Self::Custom(value) => value.downcast(),\n                    _ => None,\n                }\n            }\n\n            #[cfg(webgpu)]\n            #[inline]\n            #[allow(clippy::allow_attributes, unused)]\n            pub fn as_webgpu(&self) -> &$webgpu_type {\n                match self {\n                    Self::WebGPU(value) => value,\n                    _ => panic!(concat!(stringify!($name), \" is not webgpu\")),\n                }\n            }\n\n            #[cfg(webgpu)]\n            #[inline]\n            #[allow(clippy::allow_attributes, unused)]\n            pub fn as_webgpu_opt(&self) -> Option<&$webgpu_type> {\n                match self {\n                    Self::WebGPU(value) => Some(value),\n                    _ => None,\n                }\n            }\n\n            #[cfg(custom)]\n            #[inline]\n            pub fn custom<T: $interface>(t: T) -> Self {\n                Self::Custom($custom_type::new(t))\n            }","sourceCodeStart":834,"sourceCodeEnd":870,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu/src/dispatch.rs#L834-L870","documentation":"This panic is emitted by wgpu's generated dispatch enum accessor `as_webgpu()` (defined by the `dispatch_types!` macro in wgpu/src/dispatch.rs:852). The dispatch enum (e.g. `DispatchBindGroup`) wraps one of several backend variants (Core, WebGPU, Custom); `as_webgpu()` returns the inner `webgpu`-backend object only if the enum actually holds the `WebGPU` variant, and panics with '<Name> is not webgpu' otherwise. It exists because wgpu compiles to multiple backends behind one opaque handle type, so unchecked backend downcasts must fail loudly.","triggerScenarios":"Calling `dispatch_handle.as_webgpu()` on a handle whose enum value is `Core(...)` or `Custom(...)` — e.g. building with the native `wgpu_core` feature (as the benchmark benches/benches/wgpu-benchmark/bind_groups.rs does via DeviceState) and then calling `as_webgpu()`, or holding a handle produced by a WebGPU-backend instance in a code path that assumes a Core object.","commonSituations":"Mixing native and WASM builds: code written for the browser (WebGPU backend) is run natively where handles are Core-backed; feature-flag mismatches (webgpu enabled alongside wgpu_core) where the code assumes the wrong variant; downstream code reaching into wgpu internals during a wgpu-internal refactor.","solutions":["Use the non-panicking `as_webgpu_opt()` (returns Option<&WebGPUType>) and handle None instead","Check which backend actually constructed the handle; if running natively, use `as_core()` / `as_core_opt()`","Align cargo features so only the intended backend (wgpu_core OR webgpu) is enabled, or branch on the active feature with #[cfg]","Call methods through the Deref target (`dyn` interface trait) instead of downcasting to a specific backend"],"exampleFix":"// before\nlet inner = bind_group.as_webgpu();\n// after\nlet Some(inner) = bind_group.as_webgpu_opt() else {\n    // handle Core/Custom backend case\n    return;\n};","handlingStrategy":"type-guard","validationCode":"// Compile-time: ensure the webgpu backend is the active one\n#[cfg(all(webgpu, not(wgpu_core)))]\nconst WEBGPU_ONLY: () = ();","typeGuard":"fn is_webgpu(h: &wgpu::DispatchBindGroup) -> bool {\n    h.as_webgpu_opt().is_some()\n}","tryCatchPattern":"// Panics are not catchable in Rust; avoid via Option accessor\nmatch handle.as_webgpu_opt() {\n    Some(v) => use_webgpu(v),\n    None => eprintln!(\"handle is not webgpu-backed\"),\n}","preventionTips":["Prefer as_webgpu_opt() over as_webgpu() in application code","Only call backend-specific accessors behind matching #[cfg] gates","Don't mix native and WASM builds of the same code path unguarded","Use the shared trait methods via Deref instead of backend downcasts"],"tags":["panic","webgpu","backend-mismatch","wgpu"],"backgroundTag":"wrong-backend-variant-unwrap","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}