zed-industries/zed · error

Failed to write to failed.jsonl

Error message

Failed to write to failed.jsonl

What it means

Panics when OpenOptions::open fails to open failed.jsonl in the run directory for appending. The .expect fires on any io::Error from open: the RUN_DIR timestamped directory does not exist yet, the path is read-only, disk quota is exhausted, or another process holds an incompatible lock. It fires before any write happens, so the failure is about opening the log file, not writing records to it.

Source

Thrown at crates/edit_prediction_cli/src/main.rs:1664

                &serde_json::to_vec_pretty(&example).unwrap(),
            )
            .await
            .unwrap();
        let err_path = FAILED_EXAMPLES_DIR.join(format!("{}_err.txt", example_name));
        app_state
            .fs
            .write(&err_path, format!("{error:?}").as_bytes())
            .await
            .unwrap();

        let failed_jsonl_path = RUN_DIR.join("failed.jsonl");
        let mut file = OpenOptions::new()
            .create(true)
            .append(true)
            .open(&failed_jsonl_path)
            .expect("Failed to open failed.jsonl");
        writeln!(file, "{}", serde_json::to_string(example).unwrap())
            .expect("Failed to write to failed.jsonl");

        let cursor_path = match example.repo_name() {
            Ok(repo_name) => repo_name.worktree_path().join(&example.spec.cursor_path),
            Err(_) => example.spec.cursor_path.as_ref().to_path_buf(),
        };
        msg = format!(
            indoc::indoc! {"
                While processing \"{}\":

                \x1b[31m{:?}\x1b[0m

                Example:        \x1b[36m{}\x1b[0m
                Error file:     \x1b[36m{}\x1b[0m
                Cursor file:    \x1b[36m{}\x1b[0m
                Re-run:         cargo run -p edit_prediction_cli -- {} \x1b[36m{}\x1b[0m
            "},
            example.spec.name,
            error,

View on GitHub (pinned to f4178619ac)

Solutions

  1. Replace .expect with ? and propagate the io::Error with .context("Failed to open failed.jsonl") so the caller's anyhow handler reports it
  2. Create the run directory with create_dir_all before opening the log file
  3. Fall back to writing the failed example to stderr if the jsonl file cannot be opened, so the failure record is never silently lost
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at crates/edit_prediction_cli/src/main.rs:1664 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/a7665f6e5e1da28d. Report an issue: GitHub.