{"record":{"id":"6307f7115190075c","repo":"astrid-runtime/astrid","slug":"source-as-str","errorCode":null,"errorMessage":"source.as_str()","messagePattern":"source\\.as_str\\(\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage/src/volume/hosted/mod.rs","lineNumber":341,"sourceCode":"        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()))?;\n        state.regions.insert(destination.clone(), source_state);\n        Ok(())\n    }\n\n    fn replace_region(&self, source: &VolumeRegion, destination: &VolumeRegion) -> io::Result<()> {\n        let mut state = self.state.lock();","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage/src/volume/hosted/mod.rs#L323-L359","documentation":"rename_region validates the source region exists and returns io::ErrorKind::NotFound with the source name when it is absent from state.regions. A rename needs actual region state (extents, length) to move; renaming a nonexistent source is rejected before the Rename journal record is appended.","triggerScenarios":"Calling rename_region with a source &VolumeRegion never created, already removed, already renamed away (source no longer exists after a prior successful rename), or with a name differing in case/whitespace from the created one.","commonSituations":"Retrying a rename whose first attempt succeeded (source is now the destination name); renaming regions across separate volume instances; region-name constants drifting between modules.","solutions":["Confirm the source region exists before renaming; after a successful rename, only the destination name remains valid.","Make retry logic idempotent: if the destination exists and the source does not, treat the rename as already done.","Use the exact region name string as created (watch case, extensions, path prefixes).","Match on io::ErrorKind::NotFound to return a clear 'source region not found' error."],"exampleFix":"// before\nvolume.rename_region(&src, &dst)?; // fails on retry\n// after\nif !volume.region_exists(&src) && volume.region_exists(&dst) {\n    return Ok(()); // rename already applied\n}\nvolume.rename_region(&src, &dst)?;","handlingStrategy":"validation","validationCode":"if !region_exists(&volume, &src) {\n    if region_exists(&volume, &dst) { return Ok(()); } // already renamed\n    return Err(format!(\"source region {} not found\", src.as_str()).into());\n}\nvolume.rename_region(&src, &dst)?;","typeGuard":"fn renameable(src: &VolumeRegion, dst: &VolumeRegion, existing: &[String]) -> bool {\n    existing.iter().any(|r| r == src.as_str()) && !existing.iter().any(|r| r == dst.as_str())\n}","tryCatchPattern":"match volume.rename_region(&src, &dst) {\n    Err(e) if e.kind() == io::ErrorKind::NotFound => eprintln!(\"source {} missing\", src.as_str()),\n    Err(e) if e.kind() == io::ErrorKind::AlreadyExists => eprintln!(\"destination {} taken\", dst.as_str()),\n    r => r?,\n}","preventionTips":["After a successful rename, update all stored references from source to destination name.","Make rename retries idempotent by checking src/dst existence first.","Define region names as shared constants to avoid cross-module typos."],"tags":["io","not-found","storage","rename"],"backgroundTag":"resource-not-found","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"}