{"record":{"id":"9b957420cd9f79fc","repo":"astrid-runtime/astrid","slug":"destination-as-str","errorCode":null,"errorMessage":"destination.as_str()","messagePattern":"destination\\.as_str\\(\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage/src/volume/hosted/mod.rs","lineNumber":335,"sourceCode":"        truncate_extents(&mut region_state.extents, length);\n        region_state.length = length;\n        Ok(())\n    }\n\n    fn remove_region(&self, region: &VolumeRegion) -> io::Result<()> {\n        let mut state = self.state.lock();\n        if !state.regions.contains_key(region) {\n            return Err(io::Error::new(io::ErrorKind::NotFound, region.as_str()));\n        }\n        Self::append(&mut state, Operation::Remove, region, 0, &[])?;\n        state.regions.remove(region);\n        Ok(())\n    }\n\n    fn rename_region(&self, source: &VolumeRegion, destination: &VolumeRegion) -> io::Result<()> {\n        let mut state = self.state.lock();\n        if state.regions.contains_key(destination) {\n            return Err(io::Error::new(\n                io::ErrorKind::AlreadyExists,\n                destination.as_str(),\n            ));\n        }\n        if !state.regions.contains_key(source) {\n            return Err(io::Error::new(io::ErrorKind::NotFound, source.as_str()));\n        }\n        Self::append(\n            &mut state,\n            Operation::Rename,\n            source,\n            0,\n            destination.as_str().as_bytes(),\n        )?;\n        let source_state = state\n            .regions\n            .remove(source)\n            .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, source.as_str()))?;","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage/src/volume/hosted/mod.rs#L317-L353","documentation":"rename_region rejects the operation with io::ErrorKind::AlreadyExists and the destination name when a region with that name already exists in the volume. Renames must produce a fresh name; the library refuses to silently overwrite an existing region (use replace_region for overwrite semantics).","triggerScenarios":"Calling rename_region(source, destination) where state.regions already contains destination: renaming onto a region created earlier, renaming to the region's own current name, or a leftover destination region from a prior run persisted in the volume file.","commonSituations":"Retry logic re-attempting a rename that already succeeded; installing a new generation over an old region name without deleting the old one first; generated destination names colliding (e.g. same timestamp); user expecting POSIX rename() overwrite semantics.","solutions":["Use replace_region instead when overwrite of an existing destination is intended.","Delete the existing destination with remove_region before renaming, if the old contents are disposable.","Generate a unique destination name (counter/uuid suffix) when creating new generations.","Catch io::ErrorKind::AlreadyExists and branch to overwrite-or-skip logic at the call site."],"exampleFix":"// before\nvolume.rename_region(&src, &dst)?; // AlreadyExists if dst exists\n// after\nif volume.region_exists(&dst) {\n    volume.replace_region(&src, &dst)?;\n} else {\n    volume.rename_region(&src, &dst)?;\n}","handlingStrategy":"validation","validationCode":"if region_exists(&volume, &dst) {\n    volume.replace_region(&src, &dst)?; // or remove dst first\n} else {\n    volume.rename_region(&src, &dst)?;\n}","typeGuard":"fn rename_target_free(dst: &VolumeRegion, existing: &[String]) -> bool {\n    !existing.iter().any(|r| r == dst.as_str())\n}","tryCatchPattern":"if let Err(e) = volume.rename_region(&src, &dst) {\n    if e.kind() == io::ErrorKind::AlreadyExists {\n        // choose: overwrite via replace_region, or skip as already-done\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Use unique destination names (uuid/monotonic counter) for new generations.","Remember rename_region never overwrites; reach for replace_region for swap-over semantics.","In retry logic, check whether the rename already succeeded (src gone, dst present).","Clean up stale destination regions left by previous failed runs."],"tags":["io","already-exists","storage","rename"],"backgroundTag":"file-already-exists","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}