{"record":{"id":"a6429db8e518180f","repo":"sxyazi/yazi","slug":"url-path-kind-does-not-match-auth-kind","errorCode":null,"errorMessage":"URL path kind does not match Auth kind","messagePattern":"URL path kind does not match Auth kind","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/url/cow.rs","lineNumber":207,"sourceCode":"\twhere\n\t\tS: serde::Serializer,\n\t{\n\t\tself.as_url().serialize(serializer)\n\t}\n}\n\nimpl<'de> Deserialize<'de> for UrlCow<'_> {\n\tfn deserialize<D>(deserializer: D) -> Result<Self, D::Error>\n\twhere\n\t\tD: Deserializer<'de>,\n\t{\n\t\tUrlBuf::deserialize(deserializer).map(UrlCow::from)\n\t}\n}\n\nfn validate_auth_path(auth: &AuthArc, path: PathDyn) -> Result<()> {\n\tauth.validate()?;\n\tensure!(auth.path_kind()? == path.kind(), \"URL path kind does not match Auth kind\");\n\n\tif auth.kind.is_hub() {\n\t\tensure!(\n\t\t\tauth.parent_depth() == path.components().auth_depth(),\n\t\t\t\"Hub URL parent depth does not match its path\"\n\t\t);\n\t}\n\tOk(())\n}\n\n#[cfg(test)]\nmod tests {\n\tuse super::*;\n\tuse crate::url::UrlLike;\n\n\t#[test]\n\tfn test_parse() -> Result<()> {\n\t\tcrate::init_tests();","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/sxyazi/yazi/blob/8ebf930f1796ae2076b7d6b0c5e93a1002c18134/yazi-shared/src/url/cow.rs#L189-L225","documentation":"validate_auth_path pairs an AuthArc with a PathDyn and checks they agree: the auth's path kind (derived from its scheme) must equal the path's kind. A mismatch (e.g. Unix auth with an OS/Windows path) means the URL was assembled from incompatible parts, so validation fails. It also checks hub parent depth consistency after this check.","triggerScenarios":"Calling `UrlCow::try_from(...)` or `with_ports` with an auth and path whose kinds disagree — e.g. deserializing a URL whose auth is Sftp/Unix but whose path component is a Windows-style OS path, or vice versa.","commonSituations":"Hand-editing or migrating serialized URL/auth state across platforms; constructing UrlCow manually from mixed sources (Unix loc + OS path); restoring a cache written on a different OS.","solutions":["Make the path kind match the auth kind — use a Unix path for Unix/Sftp auths and an OS path for local auths.","Reconstruct the URL from its canonical parts (scheme, auth, loc) using the Url/UrlBuf constructors instead of splicing raw paths.","Regenerate serialized state with the same platform/version that will consume it."],"exampleFix":"// before\nlet cow = UrlCow::try_from((unix_auth, PathDyn::os(\"C:\\\\data\")))?;\n// after\nlet cow = UrlCow::try_from((unix_auth, PathDyn::unix(\"/data\")))?;","handlingStrategy":"validation","validationCode":"// before constructing UrlCow\nif auth.path_kind()? != path.kind() {\n    return Err(anyhow!(\"auth/path kind mismatch\"));\n}","typeGuard":"fn kinds_match(auth: &AuthArc, path: PathDyn) -> bool { auth.path_kind().map(|k| k == path.kind()).unwrap_or(false) }","tryCatchPattern":"// on deserialization\nlet cow = UrlCow::try_from(raw).context(\"invalid serialized URL: auth/path mismatch\")?;","preventionTips":["Construct URLs from canonical parts rather than splicing raw path strings.","Don't move serialized URL state across platforms without regenerating it.","Check path kind against scheme whenever assembling auth + path manually."],"tags":["url","auth","path","validation","rust"],"backgroundTag":"type-mismatch","analyzedSha":"8ebf930f1796ae2076b7d6b0c5e93a1002c18134","analyzedAt":"2026-09-09T22:26:16.379Z","contentChangedAt":"2026-09-09T22:26:16.379Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}