{"record":{"id":"c26c75c338a4f5b5","repo":"zed-industries/zed","slug":"the-entity-must-be-alive-if-we-have-a-entity-conte","errorCode":null,"errorMessage":"The entity must be alive if we have a entity context","messagePattern":"The entity must be alive if we have a entity context","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui/src/app/context.rs","lineNumber":54,"sourceCode":"        self.app\n    }\n}\n\nimpl<'a, T: 'static> Context<'a, T> {\n    pub(crate) fn new_context(app: &'a mut App, entity_state: WeakEntity<T>) -> Self {\n        Self { app, entity_state }\n    }\n\n    /// The entity id of the entity backing this context.\n    pub fn entity_id(&self) -> EntityId {\n        self.entity_state.entity_id\n    }\n\n    /// Returns a handle to the entity belonging to this context.\n    pub fn entity(&self) -> Entity<T> {\n        self.weak_entity()\n            .upgrade()\n            .expect(\"The entity must be alive if we have a entity context\")\n    }\n\n    /// Returns a weak handle to the entity belonging to this context.\n    pub fn weak_entity(&self) -> WeakEntity<T> {\n        self.entity_state.clone()\n    }\n\n    /// Arranges for the given function to be called whenever [`Context::notify`] is\n    /// called with the given entity.\n    pub fn observe<W>(\n        &mut self,\n        entity: &Entity<W>,\n        mut on_notify: impl FnMut(&mut T, Entity<W>, &mut Context<T>) + 'static,\n    ) -> Subscription\n    where\n        T: 'static,\n        W: 'static,\n    {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/gpui/src/app/context.rs#L36-L72","documentation":"Context<'a, T>::entity upgrades the stored WeakEntity<T>. A Context only exists while its entity is being updated, so the weak handle must be upgradeable; a panic here means the entity was released mid-update, e.g. it dropped itself (cx.emit into release) or was otherwise removed during its own context's lifetime.","triggerScenarios":"Thrown at crates/gpui/src/app/context.rs:53 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Find code that releases the entity during its own update (self-drop, releasing via a callback)","Avoid dropping the last strong handle to the entity from within its own context callbacks","Use weak_entity() APIs if the entity may legitimately be gone"],"exampleFix":null,"handlingStrategy":"validation","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"}