astrid-runtime/astrid · warning

AlreadyExists

AlreadyExists

Error message

private Windows directory already exists: {}

What it means

`create_private_descendants` computes the list of new directory components to create under the trusted handle; if that list is empty, there is nothing to create and the target already exists as-is. The library treats this as `AlreadyExists` rather than silently succeeding, so callers can distinguish 'created' from 'was already there'.

Source

Thrown at crates/astrid-core/src/platform_fs/windows/path.rs:338

                    target.display()
                ),
            )
        })?;
        let names = relative
            .components()
            .map(|component| match component {
                Component::Normal(name) => Ok(name.to_os_string()),
                _ => Err(io::Error::new(
                    io::ErrorKind::InvalidInput,
                    format!(
                        "private Windows directory contains a non-normal component: {}",
                        target.display()
                    ),
                )),
            })
            .collect::<io::Result<Vec<_>>>()?;
        if names.is_empty() {
            return Err(io::Error::new(
                io::ErrorKind::AlreadyExists,
                format!(
                    "private Windows directory already exists: {}",
                    target.display()
                ),
            ));
        }

        let mut created = CreatedPrivateDirectories::with_capacity(names.len());
        let result = (|| {
            self.verify_contract(BoundaryContract::TrustedForCreate)?;
            let mut current = self.authority_boundary.clone();
            for (index, name) in names.iter().enumerate() {
                let parent = created
                    .last_handle()
                    .unwrap_or_else(|| self.authority_handle());
                current.push(name);
                let handle = create_private_directory_relative(parent, name)?;

View on GitHub (pinned to affd8760f4)

Solutions

  1. Check `target.exists()` (or match on the AlreadyExists error) and treat it as success if idempotent behavior is desired
  2. Pass a target strictly below the boundary with at least one new component
  3. Use a different directory name if a fresh directory is required

Example fix

// before
create_private_descendants(&boundary_root)?; // nothing to create
// after
let target = boundary_root.join("private");
match create_private_descendants(&target) {
    Err(e) if e.kind() == io::ErrorKind::AlreadyExists => { /* reuse existing */ }
    other => other?,
}
Defensive patterns

Strategy: try-catch

Validate before calling

if target.strip_prefix(&boundary_root).map(|r| r.as_os_str().is_empty()).unwrap_or(true) {
    // target has no new descendants to create
}

Type guard

fn has_new_components(boundary: &Path, target: &Path) -> bool {
    target.strip_prefix(boundary).map(|r| !r.as_os_str().is_empty()).unwrap_or(false)
}

Try / catch

match create_private_descendants(&target) {
    Err(e) if e.kind() == io::ErrorKind::AlreadyExists => { /* reuse existing directory */ }
    Err(e) => return Err(e),
    Ok(()) => {}
}

Prevention

When it happens

Trigger: Calling the create path with a target equal to the authority boundary itself (empty relative remainder), so no descendant components need creating.

Common situations: Idempotent startup code that re-creates the private root every launch; passing the boundary directory instead of a subdirectory; a config value defaulting to the boundary root.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/8eaa0a2c1759521a. Report an issue: GitHub.