{"record":{"id":"cf8fe8902776a0cb","repo":"neon-bindings/neon","slug":"failed-to-downcast-any","errorCode":null,"errorMessage":"Failed to downcast Any","messagePattern":"Failed to downcast Any","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/neon/src/types_impl/boxed.rs","lineNumber":216,"sourceCode":"    unsafe fn from_local(env: Env, local: raw::Local) -> Self {\n        let raw_data = unsafe { maybe_external_deref(env, local) }\n            .expect(\"Failed to unwrap napi_external as Box<Any>\")\n            .downcast_ref()\n            .expect(\"Failed to downcast Any\");\n\n        Self(JsBoxInner { local, raw_data })\n    }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/neon-bindings/neon/blob/38960e4381d9ad13b551cdf2d261f609167c9bc2/crates/neon/src/types_impl/boxed.rs#L198-L234","documentation":"In `JsBox::from_local`, the external data was successfully unwrapped to a `&Box<dyn Any>`, but `downcast_ref::<T>()` returned None: the boxed Rust value's concrete type is not `T`. The handle IS a Neon JsBox, but of a different inner type, and reconstructing it as `JsBox<T>` would be unsound, so it panics instead.","triggerScenarios":"`from_local::<T>` panics when the `Box<dyn Any>` stored in the napi_external cannot be downcast to `T` — a JsBox of type U is treated as JsBox<T> (type confusion between two boxed Rust types).","commonSituations":"Casting a `JsBox<UserRecord>` to `JsBox<OtherType>`; changed Rust struct layouts across addon versions where a cached JS-side handle from an old build is reused; generic code assuming a single boxed type.","solutions":["Use the exact same T that was passed to `JsBox::new` when converting the handle","Use `JsBox::downcast` which returns Option<Self> for safe fallible conversion","Reload the addon so stale JS-held handles from a previous binary are not mixed with new types","Add a type tag or discriminant in the boxed value if multiple boxed types must be distinguished at runtime"],"exampleFix":"Request the correct JsBox<T> matching the type originally boxed with `JsBox::new`, or use `downcast` (returns Option) and handle the mismatch gracefully instead of from_local.","handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep boxed types stable across addon releases or invalidate old handles","Prefer the fallible `downcast` path whenever the input type is not statically known"],"tags":[],"backgroundTag":null,"analyzedSha":"38960e4381d9ad13b551cdf2d261f609167c9bc2","analyzedAt":"2026-09-13T09:05:33.640Z","contentChangedAt":"2026-09-13T09:05:33.640Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}