zed-industries/zed · error

cannot call save_as on an excerpt list

Error message

cannot call save_as on an excerpt list

What it means

A type guard on BufferItemHandle::save_as: saving under a new path writes a single file, so it calls as_singleton().expect and panics when the editor's buffer is a multi-buffer/excerpt list, for which 'save as one file' is undefined. It fires when a caller routes a save_as through an editor that holds excerpts from multiple files instead of a singleton buffer.

Source

Thrown at crates/editor/src/items.rs:1034

            if !buffers_to_save.is_empty() {
                project
                    .update(cx, |project, cx| {
                        project.save_buffers(buffers_to_save.clone(), cx)
                    })
                    .await?;
            }

            Ok(())
        })
    }

    fn save_as(
        &mut self,
        project: Entity<Project>,
        path: ProjectPath,
        _: &mut Window,
        cx: &mut Context<Self>,
    ) -> Task<Result<()>> {
        let buffer = self
            .buffer()
            .read(cx)
            .as_singleton()
            .expect("cannot call save_as on an excerpt list");

        let file_extension = path.path.extension().map(|a| a.to_string());
        self.report_editor_event(
            ReportEditorEvent::Saved { auto_saved: false },
            file_extension,
            cx,
        );

        project.update(cx, |project, cx| project.save_buffer_as(buffer, path, cx))
    }

    fn reload(

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Check as_singleton() and return a Task resolving to an error (or bail with 'cannot save an excerpt list as a single file') instead of panicking
  2. Route multi-buffer saves through the multi-buffer save API or disallow the action for excerpt lists
  3. Disable the Save As action in the UI when the active editor is not a singleton buffer
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/editor/src/items.rs:1026 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/ac0a04f415439442. Report an issue: GitHub.