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
- Pass create_new=false if the region existing is acceptable (idempotent create)
- Check region_exists() first when you need to distinguish fresh vs existing
- Treat io::ErrorKind::AlreadyExists as success in idempotent initialization paths
- Fix double-initialization logic so exclusive create runs only once
Example fix
// before volume.create_region(®ion, true)?; // fails on restart // after volume.create_region(®ion, false)?; // idempotent
Defensive patterns
Strategy: try-catch
Validate before calling
if volume.region_exists(®ion)? && 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(®ion, true) {
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()), // idempotent init
other => other,
} Prevention
- Use create_new=false for idempotent initialization
- Reserve create_new=true for exclusive-create flows that handle the collision
- Guard concurrent creation with an external lock if needed
When it happens
Trigger: Calling create_region(®ion, 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
- destination.as_str()
- audit read failed
- invalid Astrid volume record length at
- invalid interior Astrid volume record length at
- non-UTF-8 region name
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.stateView on GitHub (pinned to affd8760f4)