{"record":{"id":"166d18dd310fca26","repo":"zed-industries/zed","slug":"invalid-entity-type","errorCode":null,"errorMessage":"invalid entity type","messagePattern":"invalid entity type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui/src/app.rs","lineNumber":2175,"sourceCode":"\n    pub(crate) fn new_entity_observer(\n        &self,\n        key: TypeId,\n        value: NewEntityListener,\n    ) -> Subscription {\n        let (subscription, activate) = self.new_entity_observers.insert(key, value);\n        activate();\n        subscription\n    }\n\n    /// Arrange for the given function to be invoked whenever a view of the specified type is created.\n    /// The function will be passed a mutable reference to the view along with an appropriate context.\n    pub fn observe_new<T: 'static>(\n        &self,\n        on_new: impl 'static + Fn(&mut T, Option<&mut Window>, &mut Context<T>),\n    ) -> Subscription {\n        self.new_entity_observer(\n            TypeId::of::<T>(),\n            Box::new(\n                move |any_entity: AnyEntity, window: &mut Option<&mut Window>, cx: &mut App| {\n                    any_entity\n                        .downcast::<T>()\n                        .unwrap()\n                        .update(cx, |entity_state, cx| {\n                            on_new(entity_state, window.as_deref_mut(), cx)\n                        })\n                },\n            ),\n        )\n    }\n\n    /// Observe the release of a entity. The callback is invoked after the entity\n    /// has no more strong references but before it has been dropped.\n    pub fn observe_release<T>(\n        &self,\n        handle: &Entity<T>,","sourceCodeStart":2157,"sourceCodeEnd":2193,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/gpui/src/app.rs#L2157-L2193","documentation":"A type-downcast guard in observe_release's release listener: entities are stored as AnyEntity and the callback receives &mut dyn Any, which is downcast to T — the type observe_release was registered for. The expect ('invalid entity type') fires only if the release listener for entity id X is invoked with an entity whose concrete type differs from the registration's T, i.e. entity ids were reused or release listeners were routed to the wrong slot — an internal bookkeeping error.","triggerScenarios":"Thrown at crates/gpui/src/app.rs:2138 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check downcast_mut() and skip the callback when the type mismatches, logging the entity id mismatch","Store the expected TypeId alongside each release listener and verify before dispatch","Ensure release listeners are fully removed when an entity is dropped so ids are never reused with stale listeners"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}