{"record":{"id":"f92d689975e6097d","repo":"zed-industries/zed","slug":"invalid-event-type","errorCode":null,"errorMessage":"invalid event type","messagePattern":"invalid event type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui/src/app.rs","lineNumber":1221,"sourceCode":"    ) -> Subscription\n    where\n        T: 'static + EventEmitter<Event>,\n        Event: 'static,\n    {\n        self.subscribe_internal(entity, move |entity, event, cx| {\n            on_event(entity, event, cx);\n            true\n        })\n    }\n\n    pub(crate) fn new_subscription(\n        &mut self,\n        key: EntityId,\n        value: (TypeId, Listener),\n    ) -> Subscription {\n        let (subscription, activate) = self.event_listeners.insert(key, value);\n        self.defer(move |_| activate());\n        subscription\n    }\n    pub(crate) fn subscribe_internal<T, Evt>(\n        &mut self,\n        entity: &Entity<T>,\n        mut on_event: impl FnMut(Entity<T>, &Evt, &mut App) -> bool + 'static,\n    ) -> Subscription\n    where\n        T: 'static + EventEmitter<Evt>,\n        Evt: 'static,\n    {\n        let entity_id = entity.entity_id();\n        let handle = entity.downgrade();\n        self.new_subscription(\n            entity_id,\n            (\n                TypeId::of::<Evt>(),\n                Box::new(move |event, cx| {\n                    let event: &Evt = event.downcast_ref().expect(\"invalid event type\");","sourceCodeStart":1203,"sourceCodeEnd":1239,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/gpui/src/app.rs#L1203-L1239","documentation":"A type-downcast guard in GPUI's subscription dispatch: subscribe_internal stores a closure keyed by TypeId of the event type Evt, and when an event is delivered it downcast_ref::<Evt>().expect('invalid event type') fires if the boxed event's dynamic type does not match the Evt the callback was registered for. That can only happen if event routing delivers an event to a subscription registered under a different TypeId — a dispatcher/registry bug, not caller error.","triggerScenarios":"Thrown at crates/gpui/src/app.rs:1210 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace expect with downcast_ref plus an early return (or debug assertion) so a misrouted event is dropped/logged rather than crashing the app","Key subscription slots by (TypeId, event TypeId) so mismatched delivery cannot occur","Add tests that emit each event type and assert only matching subscribers are invoked"],"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"}