SeleniumHQ/selenium · error · anyhow::Error

The file {} already exists. Please remove it or choose a dif

Error message

The file {} already exists. Please remove it or choose a different location.

What it means

Returned by write_rules_file() in rules.rs when the destination path already exists. The function deliberately refuses to overwrite so user edits to the rules file are preserved. The placeholder is the path.

Source

Thrown at rust/src/rules.rs:37

use anyhow::{Error, anyhow};
use std::fs::OpenOptions;
use std::io::Write;
use std::path::Path;

const RULES_CONTENT: &str = include_str!("resources/rules.md");

/// Writes the Selenium LLM rules file to the given path, creating parent directories as needed.
///
/// # Arguments
/// * `path` - Destination file path (e.g. `rules/selenium.md`)
/// * `log` - Logger instance
///
/// # Errors
/// Returns an error if the file already exists or cannot be written.
pub fn write_rules_file(path: &Path, log: &Logger) -> Result<(), Error> {
    log.debug(format!("Creating rules file at: {}", path.display()));
    if path.exists() {
        return Err(anyhow!(
            "The file {} already exists. Please remove it or choose a different location.",
            path.display()
        ));
    }
    if let Some(parent) = path.parent() {
        if !parent.exists() {
            log.debug(format!("Creating directory: {}", parent.display()));
            std::fs::create_dir_all(parent)?;
        }
    }
    let mut file = OpenOptions::new().write(true).create_new(true).open(path)?;
    file.write_all(RULES_CONTENT.as_bytes())?;
    Ok(())
}

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Remove or rename the existing file before re-running.
  2. Point the command at a different destination path.
  3. If regenerating intentionally, delete the file first (rm rules/selenium.md).

Example fix

# before
selenium-manager --gen-rules rules/selenium.md   # already exists
# after
rm rules/selenium.md && selenium-manager --gen-rules rules/selenium.md
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;
if Path::new(path).exists() {
    return Err(anyhow!("rules file already exists at {path}; remove it first"));
}
write_rules_file(Path::new(path), &log)?;

Prevention

When it happens

Trigger: write_rules_file(path, log) is called with a path for which path.exists() is true (rules.rs:36-41).

Common situations: Re-running a setup/generation command that already wrote rules/selenium.md; the file was committed to a repo and the command is run again in CI.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/f4a4483c071db204. Report an issue: GitHub.