{"record":{"id":"ef1aeddbd30e657b","repo":"astrid-runtime/astrid","slug":"layout-destination-path-cannot-be-represented-loss","errorCode":null,"errorMessage":"layout destination path cannot be represented losslessly on this platform","messagePattern":"layout destination path cannot be represented losslessly on this platform","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/astrid-core/src/dirs_layout_records.rs","lineNumber":249,"sourceCode":"pub(super) fn encoded_bytes_to_os_string(bytes: Vec<u8>) -> io::Result<OsString> {\n    use std::os::unix::ffi::OsStringExt as _;\n\n    // Unix receipts commit to the raw OsStr byte sequence, including paths\n    // that are not UTF-8. Decoding must therefore preserve every byte.\n    Ok(OsString::from_vec(bytes))\n}\n\n#[cfg(not(unix))]\npub(super) fn encoded_bytes_to_os_string(bytes: Vec<u8>) -> io::Result<OsString> {\n    let text = String::from_utf8(bytes).map_err(|error| {\n        io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"layout destination path is not portable UTF-8: {error}\"),\n        )\n    })?;\n    let path = OsString::from(&text);\n    if path.as_encoded_bytes() != text.as_bytes() {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"layout destination path cannot be represented losslessly on this platform\",\n        ));\n    }\n    Ok(path)\n}\n\npub(super) fn inventory_tree(path: &Path) -> io::Result<LayoutTreeIdentityV1> {\n    let mut hasher = blake3::Hasher::new_derive_key(\"astrid layout source inventory v1\");\n    let mut entries = 0_u64;\n    let mut bytes = 0_u64;\n    match std::fs::symlink_metadata(path) {\n        Err(error) if error.kind() == io::ErrorKind::NotFound => {\n            hasher.update(b\"absent\");\n        },\n        Err(error) => return Err(error),\n        Ok(metadata) if metadata.file_type().is_symlink() || !metadata.is_dir() => {\n            return Err(io::Error::new(","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-core/src/dirs_layout_records.rs#L231-L267","documentation":"On non-Unix platforms, after decoding the bytes as UTF-8, encoded_bytes_to_os_string checks that OsString::from(text).as_encoded_bytes() equals the original text bytes — i.e. that the path can be represented losslessly in the platform's native path encoding (Windows uses WTF-16, which can reject certain code points). If the round-trip is not byte-identical, this InvalidData error is raised rather than silently producing a different path.","triggerScenarios":"Calling physical_path / encoded_bytes_to_os_string on Windows with UTF-8 text containing unpaired surrogates or code points that do not round-trip through the OS's OsString encoding.","commonSituations":"Paths written on Linux with weird/nonstandard Unicode (e.g. lone surrogate encodings via invalid WTF-8) later resolved on Windows; records produced by an older library version with laxer path encoding.","solutions":["Rename the destination to use standard Unicode (BMP) characters that round-trip on all platforms, then reissue the record.","Regenerate layout records on the target platform so the encoded form matches its native encoding.","Drop to ASCII-only path components if cross-platform portability is required."],"exampleFix":"// before: path with exotic code point\nlet dest = Path::new(\"/data/vol\\u{D800}x\"); // unpaired surrogate\n// after\nlet dest = Path::new(\"/data/vol_x\");","handlingStrategy":"validation","validationCode":"let text = String::from_utf8(&encoded_bytes)?;\nlet os = std::ffi::OsString::from(&text);\nif os.as_encoded_bytes() != text.as_bytes() {\n    return Err(\"path does not round-trip on this platform; use standard Unicode names\");\n}","typeGuard":null,"tryCatchPattern":"match physical_path(&destination) {\n    Err(e) if e.to_string().contains(\"losslessly\") => rename_to_portable_path_and_reissue(),\n    other => other,\n}","preventionTips":["Restrict cross-platform volume names to BMP Unicode or ASCII.","Avoid exotic/invalid Unicode (unpaired surrogates) in paths.","Generate layout records on the platform where they will be consumed."],"tags":["filesystem","encoding","portability","windows"],"backgroundTag":"unsupported-platform","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}