zed-industries/zed · error

Failed to create directory

Error message

Failed to create directory

What it means

A generic guard inside the ensure_dir helper: it calls create_dir_all on the resolved data directory (repos/, worktrees/, runs/, latest/, ...) and panics if the OS reports an error. The input at fault is the derived directory path under DATA_DIR — it fires for permission denials, a parent that is a file, read-only mounts, or I/O errors, not for the common 'already exists' case which create_dir_all tolerates.

Source

Thrown at crates/edit_prediction_cli/src/paths.rs:29

pub static REPOS_DIR: LazyLock<PathBuf> = LazyLock::new(|| ensure_dir(&DATA_DIR.join("repos")));
pub static WORKTREES_DIR: LazyLock<PathBuf> =
    LazyLock::new(|| ensure_dir(&DATA_DIR.join("worktrees")));
pub static RUN_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
    DATA_DIR
        .join("runs")
        .join(chrono::Local::now().format("%d-%m-%y-%H_%M_%S").to_string())
});
pub static LATEST_EXAMPLE_RUN_DIR: LazyLock<PathBuf> = LazyLock::new(|| DATA_DIR.join("latest"));
pub static LATEST_FAILED_EXAMPLES_DIR: LazyLock<PathBuf> =
    LazyLock::new(|| DATA_DIR.join("latest_failed"));
pub static LLM_CACHE_DB: LazyLock<PathBuf> = LazyLock::new(|| CACHE_DIR.join("llm_cache.sqlite"));
pub static SYNTHESIZE_STATE_FILE: LazyLock<PathBuf> =
    LazyLock::new(|| DATA_DIR.join("synthesize_state.json"));
pub static FAILED_EXAMPLES_DIR: LazyLock<PathBuf> =
    LazyLock::new(|| ensure_dir(&RUN_DIR.join("failed")));

fn ensure_dir(path: &Path) -> PathBuf {
    std::fs::create_dir_all(path).expect("Failed to create directory");
    path.to_path_buf()
}

View on GitHub (pinned to f4178619ac)

Solutions

  1. Change ensure_dir to return io::Result<PathBuf> and propagate the error instead of panicking inside LazyLock::new
  2. Print an actionable message naming the directory and the underlying io::Error kind before exiting
  3. Check parent directory permissions and disk availability at CLI startup before the LazyLock statics are first touched
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at crates/edit_prediction_cli/src/paths.rs:29 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/4352d930eec4472c. Report an issue: GitHub.