{"record":{"id":"4feba72572cb2c6e","repo":"cross-rs/cross","slug":"unix-paths-cannot-handle-windows-prefix-prefix","errorCode":null,"errorMessage":"unix paths cannot handle windows prefix {prefix:?}.","messagePattern":"unix paths cannot handle windows prefix (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/file.rs","lineNumber":95,"sourceCode":"    }\n}\n\nimpl PathExt for Path {\n    fn as_posix_relative(&self) -> Result<String> {\n        if cfg!(target_os = \"windows\") {\n            let push = |p: &mut String, c: &str| {\n                if !p.is_empty() && p != \"/\" {\n                    p.push('/');\n                }\n                p.push_str(c);\n            };\n\n            // iterate over components to join them\n            let mut output = String::new();\n            for component in self.components() {\n                match component {\n                    Component::Prefix(prefix) => {\n                        eyre::bail!(\"unix paths cannot handle windows prefix {prefix:?}.\")\n                    }\n                    Component::RootDir => output = \"/\".to_owned(),\n                    Component::CurDir => push(&mut output, \".\"),\n                    Component::ParentDir => push(&mut output, \"..\"),\n                    Component::Normal(path) => push(&mut output, path.to_utf8()?),\n                }\n            }\n            Ok(output)\n        } else {\n            self.to_utf8().map(|x| x.to_owned())\n        }\n    }\n\n    #[cfg(not(target_family = \"windows\"))]\n    fn as_posix_absolute(&self) -> Result<String> {\n        absolute_path(self)?.to_utf8().map(ToOwned::to_owned)\n    }\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/file.rs#L77-L113","documentation":"`as_posix_relative` converts a Path to a POSIX-style relative string, but it cannot represent Windows path prefixes (drive letters like `C:` or UNC `\\\\server\\share`). If the path's components include a `Component::Prefix`, it bails because such a path has no valid POSIX relative form.","triggerScenarios":"Calling `as_posix_relative` on an absolute Windows path (e.g. `C:\\Users\\me\\project` or a UNC path) that was passed to code expecting a relative Unix-style path.","commonSituations":"Running cross on Windows or with Windows-originated paths (CARGO_TARGET_DIR, config paths) where a relative path is required inside the container; hardcoded `C:\\...` paths in cross config files.","solutions":["Pass a relative path (relative to the working directory) instead of an absolute Windows path.","Use a forward-slash path without the drive prefix, e.g. `target` instead of `C:\\project\\target`.","Run the invocation from a Unix-style environment (WSL) where paths have no Windows prefix."],"exampleFix":"// before (cross config)\n[target.x86_64-pc-windows-gnu]\n# path passed: C:\\project\\target\n// after\n# run from project root and pass relative path: target","handlingStrategy":"validation","validationCode":"function isAbsolutePathWithPrefix(p) {\n  return /^[A-Za-z]:[\\\\/]/.test(p) || /^\\\\\\\\[^\\\\]/.test(p); // C:\\ or \\\\server\\share\n}\n// before calling as_posix_relative, ensure the path has no drive/UNC prefix","typeGuard":null,"tryCatchPattern":"try {\n  return path.asPosixRelative(p);\n} catch (e) {\n  if (String(e.message).includes('windows prefix')) {\n    throw new Error(`Path ${p} must be relative and free of drive/UNC prefixes`);\n  }\n  throw e;\n}","preventionTips":["Always pass relative paths where POSIX-relative paths are required.","Avoid hardcoding `C:\\` paths in cross configuration.","Test builds on Windows early to catch prefix-carrying paths."],"tags":["windows","path","posix","cross-platform"],"backgroundTag":"invalid-argument-format","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}