{"record":{"id":"20eb853d3e7dbe7d","repo":"zed-industries/zed","slug":"update-window-returned-err-without-invoking-the-cl","errorCode":null,"errorMessage":"update_window returned Err without invoking the closure","messagePattern":"update_window returned Err without invoking the closure","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui/src/app/async_context.rs","lineNumber":393,"sourceCode":"\nimpl AppContext for AsyncWindowContext {\n    fn new<T>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T>\n    where\n        T: 'static,\n    {\n        let mut build_entity = Some(build_entity);\n        match self.app.update_window(self.window, |_, _, cx| {\n            cx.new(\n                build_entity\n                    .take()\n                    .expect(\"build_entity is taken exactly once\"),\n            )\n        }) {\n            Ok(entity) => entity,\n            Err(_) => self.app.new(\n                build_entity\n                    .take()\n                    .expect(\"update_window returned Err without invoking the closure\"),\n            ),\n        }\n    }\n\n    fn reserve_entity<T: 'static>(&mut self) -> Reservation<T> {\n        self.app.reserve_entity()\n    }\n\n    fn insert_entity<T: 'static>(\n        &mut self,\n        reservation: Reservation<T>,\n        build_entity: impl FnOnce(&mut Context<T>) -> T,\n    ) -> Entity<T> {\n        let mut args = Some((reservation, build_entity));\n        match self.app.update_window(self.window, |_, _, cx| {\n            let (reservation, build_entity) = args.take().expect(\"args are taken exactly once\");\n            cx.insert_entity(reservation, build_entity)\n        }) {","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui/src/app/async_context.rs#L375-L411","documentation":"This expect fires in AsyncWindowContext::new when App::update_window fails (window no longer exists), so the fallback path calls app.new on the main App to build the entity anyway; it panics only if the same FnOnce closure was already consumed — a logic bug, not an expected failure.","triggerScenarios":"Thrown at crates/gpui/src/app/async_context.rs:393 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify update_window's Err is due to a closed window and that the closure was never invoked before taking build_entity","Ensure the build_entity closure is only moved into one branch; take() must succeed exactly once","If this fires, audit callers passing the same closure to both update_window and the fallback new()"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}