{"record":{"id":"65cde022b71ff336","repo":"zed-industries/zed","slug":"args-are-taken-exactly-once","errorCode":null,"errorMessage":"args are taken exactly once","messagePattern":"args are taken exactly once","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui/src/app/async_context.rs","lineNumber":409,"sourceCode":"                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        }) {\n            Ok(entity) => entity,\n            Err(_) => {\n                let (reservation, build_entity) = args\n                    .take()\n                    .expect(\"update_window returned Err without invoking the closure\");\n                self.app.insert_entity(reservation, build_entity)\n            }\n        }\n    }\n\n    fn update_entity<T: 'static, R>(\n        &mut self,\n        handle: &Entity<T>,\n        update: impl FnOnce(&mut T, &mut Context<T>) -> R,\n    ) -> R {\n        self.app.update_entity(handle, update)","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui/src/app/async_context.rs#L391-L427","documentation":"In insert_entity, the (reservation, build_entity) pair is stashed in an Option; if update_window errors without running the closure the args are consumed by the fallback path. The expect panics only if both branches tried to take the same args, meaning the closure ran twice or the code was restructured incorrectly.","triggerScenarios":"Thrown at crates/gpui/src/app/async_context.rs:409 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Confirm update_window returned Err before its closure executed, so args are still Some in the fallback","Take args in exactly one of the two branches","Restructure so the reservation and closure are passed to whichever context actually runs"],"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"}