zed-industries/zed · error

args are taken exactly once

Error message

args are taken exactly once

What it means

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.

Source

Thrown at crates/gpui/src/app/async_context.rs:409

                build_entity
                    .take()
                    .expect("update_window returned Err without invoking the closure"),
            ),
        }
    }

    fn reserve_entity<T: 'static>(&mut self) -> Reservation<T> {
        self.app.reserve_entity()
    }

    fn insert_entity<T: 'static>(
        &mut self,
        reservation: Reservation<T>,
        build_entity: impl FnOnce(&mut Context<T>) -> T,
    ) -> Entity<T> {
        let mut args = Some((reservation, build_entity));
        match self.app.update_window(self.window, |_, _, cx| {
            let (reservation, build_entity) = args.take().expect("args are taken exactly once");
            cx.insert_entity(reservation, build_entity)
        }) {
            Ok(entity) => entity,
            Err(_) => {
                let (reservation, build_entity) = args
                    .take()
                    .expect("update_window returned Err without invoking the closure");
                self.app.insert_entity(reservation, build_entity)
            }
        }
    }

    fn update_entity<T: 'static, R>(
        &mut self,
        handle: &Entity<T>,
        update: impl FnOnce(&mut T, &mut Context<T>) -> R,
    ) -> R {
        self.app.update_entity(handle, update)

View on GitHub (pinned to f4178619ac)

Solutions

  1. Confirm update_window returned Err before its closure executed, so args are still Some in the fallback
  2. Take args in exactly one of the two branches
  3. Restructure so the reservation and closure are passed to whichever context actually runs
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/gpui/src/app/async_context.rs:409 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/65cde022b71ff336. Report an issue: GitHub.