zed-industries/zed · error
invalid event type
Error message
invalid event type
What it means
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.
Source
Thrown at crates/gpui/src/app.rs:1221
) -> Subscription
where
T: 'static + EventEmitter<Event>,
Event: 'static,
{
self.subscribe_internal(entity, move |entity, event, cx| {
on_event(entity, event, cx);
true
})
}
pub(crate) fn new_subscription(
&mut self,
key: EntityId,
value: (TypeId, Listener),
) -> Subscription {
let (subscription, activate) = self.event_listeners.insert(key, value);
self.defer(move |_| activate());
subscription
}
pub(crate) fn subscribe_internal<T, Evt>(
&mut self,
entity: &Entity<T>,
mut on_event: impl FnMut(Entity<T>, &Evt, &mut App) -> bool + 'static,
) -> Subscription
where
T: 'static + EventEmitter<Evt>,
Evt: 'static,
{
let entity_id = entity.entity_id();
let handle = entity.downgrade();
self.new_subscription(
entity_id,
(
TypeId::of::<Evt>(),
Box::new(move |event, cx| {
let event: &Evt = event.downcast_ref().expect("invalid event type");View on GitHub (pinned to 9d272b0363)
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
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/gpui/src/app.rs:1210 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20).
Data as JSON: /api/errors/f92d689975e6097d.
Report an issue: GitHub.