sinelaw/fresh · error

Buffer has no file path

Error message

Buffer has no file path

What it means

reload_with_encoding needs the buffer's backing file path to re-read it with a specific encoding, but the buffer has no associated file (in-memory/scratch buffer, or file_path() returned None). file_open_orchestrators.rs:463 combines the lookup with ok_or_else into this error.

Solutions

  1. Save the buffer to a file first so it has an associated path, then reload with the desired encoding
  2. Check buffer.file_path() before invoking reload_with_encoding and skip/disable the action for scratch buffers
  3. Open the intended file directly with the desired encoding instead of reloading a pathless buffer

Example fix

// before
editor.reload_with_encoding(buffer_id, "utf-16")?; // fails on scratch buffer
// after
if editor.buffer_file_path(buffer_id).is_some() {
    editor.reload_with_encoding(buffer_id, "utf-16")?;
} else {
    // buffer has no backing file — cannot reload
}
Defensive patterns

Strategy: validation

Validate before calling

if editor.buffer_file_path(buffer_id).is_none() {
    eprintln!("buffer has no file; save it before reloading");
    return;
}

Type guard

fn is_reloadable(editor: &Editor, id: BufferId) -> bool {
    editor.buffer_file_path(id).is_some()
}

Try / catch

match editor.reload_with_encoding(id, enc) {
    Err(e) if e.to_string() == "Buffer has no file path" => prompt_save_as_first(id)?,
    other => other,
}

Prevention

When it happens

Trigger: Calling reload_with_encoding (via handle_reload_with_encoding) on a buffer_id whose buffer is unsaved/new (never written to disk) or otherwise has file_path() == None.

Common situations: Running the reload-with-encoding command in a scratch buffer; reloading a buffer whose file was created after the buffer opened but the path was never attached; dashboards/terminal buffers that have no file.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/cd42b12151acf156. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-editor/src/app/file_open_orchestrators.rs:463

        Ok(buffer_id)
    }

    /// Reload the current file with a specific encoding.
    ///
    /// Requires the buffer to have no unsaved modifications.
    pub fn reload_with_encoding(
        &mut self,
        encoding: crate::model::buffer::Encoding,
    ) -> anyhow::Result<()> {
        let buffer_id = self.active_buffer();

        // Get the file path
        let path = self
            .buffers()
            .get(&buffer_id)
            .and_then(|s| s.buffer.file_path().map(|p| p.to_path_buf()))
            .ok_or_else(|| anyhow::anyhow!("Buffer has no file path"))?;

        // Check for unsaved modifications
        if let Some(state) = self
            .windows
            .get(&self.active_window)
            .map(|w| &w.buffers)
            .expect("active window present")
            .get(&buffer_id)
        {
            if state.buffer.is_modified() {
                anyhow::bail!("Cannot reload: buffer has unsaved modifications");
            }
        }

        // Reload the buffer with the new encoding
        let new_buffer = crate::model::buffer::Buffer::load_from_file_with_encoding(
            &path,
            encoding,

View on GitHub (pinned to 67894ca546)