{"record":{"id":"013fa5960bce9f6e","repo":"sxyazi/yazi","slug":"view-auth-requires-view-metadata","errorCode":null,"errorMessage":"View auth requires view metadata","messagePattern":"View auth requires view metadata","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/auth/auth.rs","lineNumber":60,"sourceCode":"\tpub fn is_remote(&self) -> bool { self.kind.is_sftp() || self.view.is_remote() }\n\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}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/sxyazi/yazi/blob/8ebf930f1796ae2076b7d6b0c5e93a1002c18134/yazi-shared/src/auth/auth.rs#L42-L78","documentation":"Auth::validate() enforces that any auth record whose kind is a view carries view metadata (an inner View with a source auth and wire data). If an auth is marked as a view kind but `view.auth()` returns None, the record is structurally invalid and validation bails. This prevents half-constructed view authorities from entering the URL system.","triggerScenarios":"Constructing an AuthArc/Auth with kind set to a view variant while leaving the `view` field absent/None, then calling `Auth::validate()` (directly or via `UrlBuf::into_view` / `validate_auth_path`).","commonSituations":"Hand-building view auth entries in custom fetch/preload providers; deserializing auth data from an older config or cache format that lacked view metadata; writing a plugin that clones kind info but not the view payload.","solutions":["Populate the view metadata (View { source, data }) on the auth before validating, e.g. via `UrlBuf::into_view(auth, data)` which builds it from the physical URL auth.","Check the auth kind: if you do not intend a view, use a non-view kind (Regular/Sftp/Hub) instead of a view kind.","If data came from a serialized cache/config, regenerate it with the current yazi version so view metadata is present."],"exampleFix":"// before\nlet auth = AuthArc::new(Auth { kind: AuthKind::view_default(), view: None });\n// after\nlet source = url.physical().auth().clone();\nlet auth = auth.with_view(View { source, data });\nauth.validate()?;","handlingStrategy":"validation","validationCode":"fn is_view_auth(auth: &Auth) -> bool { auth.kind.is_view() && auth.view.auth().is_some() }\n// call is_view_auth(&auth) before validate()/use","typeGuard":"fn as_view(auth: &Auth) -> Option<&View> { auth.kind.is_view().then(|| auth.view.auth()).flatten() }","tryCatchPattern":null,"preventionTips":["Always build view auth via constructors like with_view/into_view instead of struct literals.","Never set a view kind without also setting View { source, data }.","When deserializing old state, re-validate and regenerate entries missing view metadata."],"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-14T05:17:10.506Z"}