astrid-runtime/astrid · error · io::Error

region.as_str()

Error message

region.as_str()

What it means

create_region with create_new=true returns AlreadyExists when the region is already present; the error payload is the region name. It signals an exclusive-create request collided with an existing region.

Solutions

  1. Pass create_new=false if the region existing is acceptable (idempotent create)
  2. Check region_exists() first when you need to distinguish fresh vs existing
  3. Treat io::ErrorKind::AlreadyExists as success in idempotent initialization paths
  4. Fix double-initialization logic so exclusive create runs only once

Example fix

// before
volume.create_region(&region, true)?; // fails on restart
// after
volume.create_region(&region, false)?; // idempotent
Defensive patterns

Strategy: try-catch

Validate before calling

if volume.region_exists(&region)? && create_new {
    // decide: skip or surface a controlled conflict before calling
}

Type guard

fn ensure_region(v: &Volume, r: &VolumeRegion) -> io::Result<()> {
    if v.region_exists(r)? { Ok(()) } else { v.create_region(r, false) }
}

Try / catch

match volume.create_region(&region, true) {
    Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()), // idempotent init
    other => other,
}

Prevention

When it happens

Trigger: Calling create_region(&region, true) on a region that already exists, e.g. re-running initialization code that uses exclusive create semantics on every startup.

Common situations: Idempotent-init code wrongly passing create_new=true; two workers racing to create the same region; retry logic re-issuing a create after a timeout though the first succeeded.

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/b89a22156f9b3ed0. Report an issue: GitHub.

Appendix: source

Thrown at crates/astrid-storage/src/volume/hosted/mod.rs:223

        state.footer_pending = false;
        state.flush_state = FlushState::Confirmed;
        Ok(())
    }
}
impl Drop for HostedFileVolume {
    fn drop(&mut self) {
        let state = self.state.get_mut();
        let _ = Self::make_durable(state);
        let _ = fs2::FileExt::unlock(&state.file);
    }
}

impl AstridVolume for HostedFileVolume {
    fn create_region(&self, region: &VolumeRegion, create_new: bool) -> io::Result<()> {
        let mut state = self.state.lock();
        if state.regions.contains_key(region) {
            return if create_new {
                Err(io::Error::new(
                    io::ErrorKind::AlreadyExists,
                    region.as_str(),
                ))
            } else {
                Ok(())
            };
        }
        Self::append(&mut state, Operation::Create, region, 0, &[])?;
        state.regions.insert(region.clone(), RegionState::default());
        Ok(())
    }

    fn region_exists(&self, region: &VolumeRegion) -> io::Result<bool> {
        Ok(self.state.lock().regions.contains_key(region))
    }

    fn region_len(&self, region: &VolumeRegion) -> io::Result<u64> {
        self.state

View on GitHub (pinned to affd8760f4)