{"record":{"id":"dbc79f0898dc4d58","repo":"sxyazi/yazi","slug":"non-view-auth-cannot-have-view-metadata","errorCode":null,"errorMessage":"Non-view auth cannot have view metadata","messagePattern":"Non-view auth cannot have view metadata","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/auth/auth.rs","lineNumber":61,"sourceCode":"\n\t#[inline]\n\tpub fn physical(&self) -> &Self { self.view.auth().map_or(self, |a| a) }\n\n\t#[inline]\n\tpub(crate) fn path_kind(&self) -> Result<PathKind> { self.physical().kind.try_into() }\n\n\t#[inline]\n\tpub fn covariant(&self, other: &Self) -> bool { self.physical() == other.physical() }\n\n\tpub fn same_service(&self, other: &Self) -> bool {\n\t\tself.covariant(other)\n\t\t\t|| self.kind.is_hub() && other.kind.is_hub() && self.scheme == other.scheme\n\t}\n\n\tpub(crate) fn validate(&self) -> Result<()> {\n\t\tmatch (self.kind.is_view(), self.view.auth()) {\n\t\t\t(true, None) => bail!(\"View auth requires view metadata\"),\n\t\t\t(false, Some(_)) => bail!(\"Non-view auth cannot have view metadata\"),\n\t\t\t(true, Some(source)) => {\n\t\t\t\tensure!(source.is_regular() || source.kind.is_sftp(), \"View source must be Regular or Sftp\")\n\t\t\t}\n\t\t\t_ => {}\n\t\t}\n\t\tOk(())\n\t}\n\n\tpub(crate) fn parent_depth(&self) -> usize {\n\t\tlet mut depth = 0;\n\t\tlet mut parent = self.parent.as_ref();\n\t\twhile let Some(auth) = parent {\n\t\t\tdepth += 1;\n\t\t\tparent = auth.parent.as_ref();\n\t\t}\n\t\tdepth\n\t}\n}","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/sxyazi/yazi/blob/8ebf930f1796ae2076b7d6b0c5e93a1002c18134/yazi-shared/src/auth/auth.rs#L43-L79","documentation":"The mirror case of the view-auth check: a non-view auth (Regular, Sftp, Hub) must not carry view metadata. If `self.kind.is_view()` is false but `self.view.auth()` returns Some, validate() rejects it as contradictory. View metadata is only meaningful on view-kind authorities.","triggerScenarios":"Calling `Auth::validate()` on an auth whose kind is not a view but whose `view` field is set to Some, e.g. by reusing a previously-view auth builder or converting a view auth to another kind without clearing the view field.","commonSituations":"Mutating auth kind (e.g. demoting a view to regular) without dropping the view payload; copying auth structs field-by-field and keeping stale view data; cache entries written by a buggy intermediate version.","solutions":["Clear the view metadata (set `view` to None / omit it) for non-view kinds before validating.","If the auth really is a view, set its kind to the intended view variant instead.","Rebuild the auth from scratch with the correct kind and metadata rather than mutating kind in place."],"exampleFix":"// before\nlet auth = regular_auth.with_view(stale_view);\nauth.validate()?;\n// after\nlet auth = regular_auth; // no view metadata on non-view kinds\nauth.validate()?;","handlingStrategy":"validation","validationCode":"fn auth_is_consistent(auth: &Auth) -> bool { auth.kind.is_view() == auth.view.auth().is_some() }","typeGuard":"fn view_meta(auth: &Auth) -> Option<&View> { auth.kind.is_view().then(|| auth.view.auth()).flatten() }","tryCatchPattern":null,"preventionTips":["When changing an auth's kind, clear or rebuild its view metadata in the same step.","Avoid field-by-field cloning of auth structs; use constructors.","Treat kind and view metadata as a single invariant unit."],"tags":["auth","validation","url","rust"],"backgroundTag":"schema-validation-failed","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"}