{"record":{"id":"8e5a99a46fdece85","repo":"sxyazi/yazi","slug":"not-a-sftp-url-url","errorCode":null,"errorMessage":"Not a SFTP URL: {url:?}","messagePattern":"Not a SFTP URL: (.+?)","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"yazi-vfs/src/engine/sftp/sftp.rs","lineNumber":161,"sourceCode":"\tasync fn reroute(&self) -> io::Result<File> {\n\t\tif self.url.is_absolute() {\n\t\t\treturn Err(io::ErrorKind::Unsupported.into());\n\t\t}\n\n\t\tlet url = self.canonicalize().await?;\n\t\tSelf::new(url.as_url()).await?.file().await\n\t}\n\n\tasync fn remove_dir(&self) -> io::Result<()> { Ok(self.op().await?.rmdir(self.path).await?) }\n\n\tasync fn remove_file(&self) -> io::Result<()> { Ok(self.op().await?.remove(self.path).await?) }\n\n\tasync fn rename<P>(&self, to: P) -> io::Result<()>\n\twhere\n\t\tP: DynPath,\n\t{\n\t\tlet to = to.dyn_path().as_unix()?;\n\t\tlet op = self.op().await?;\n\n\t\tmatch op.rename_posix(self.path, &to).await {\n\t\t\tOk(()) => {}\n\t\t\tErr(yazi_sftp::Error::Unsupported) => {\n\t\t\t\tmatch op.remove(&to).await.map_err(io::Error::from) {\n\t\t\t\t\tOk(()) => {}\n\t\t\t\t\tErr(e) if e.kind() == io::ErrorKind::NotFound => {}\n\t\t\t\t\tErr(e) => Err(e)?,\n\t\t\t\t}\n\t\t\t\top.rename(self.path, &to).await?;\n\t\t\t}\n\t\t\tErr(e) => Err(e)?,\n\t\t}\n\t\tOk(())\n\t}\n\n\tasync fn set_attrs(&self, attrs: yazi_fs::engine::Attrs) -> io::Result<()> {\n\t\tlet attrs = super::Attrs(attrs)","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/sxyazi/yazi/blob/a541adde4e5b082719a0f21a87eb3eab071ece58/yazi-vfs/src/engine/sftp/sftp.rs#L143-L179","documentation":"The SFTP engine's constructor requires a `Url::Sftp { loc, auth }` variant; any other URL is rejected with InvalidInput and a message naming the actual variant received. It's a routing/type error: the SFTP engine was asked to operate on a location that isn't owned by the SFTP backend.","triggerScenarios":"Calling SFTP-backed file operations with a local, Mount/Hub/Scope (custom Lua VFS), Archive, or Search URL; or a URL that was re-parented/rewritten so it lost its Sftp variant.","commonSituations":"Plugin or config code constructing URLs manually instead of through the VFS, tab previews mixing local and remote entries, or upgrades that changed URL variant names leaving stale constructed URLs.","solutions":["Verify the URL kind before calling: it must be `Url::Sftp`; add an assertion/guard on `url.kind()`/variant","Route the operation through the generic VFS dispatcher (`yazi-vfs`) so the correct engine is selected by URL kind instead of calling the SFTP engine directly","Fix code that reconstructs the URL (e.g. joining with a local path) and preserve the original Sftp URL","Confirm the remote entry was mounted/created via SFTP APIs, not copied from a local listing"],"exampleFix":"// before\nlet file = SftpFile::new(some_local_url)?; // panics into InvalidInput\n// after\nif let Url::Sftp { .. } = &url {\n    let file = SftpFile::new(url)?;\n} else {\n    return engine::open(url).await; // generic dispatch\n}","handlingStrategy":"type-guard","validationCode":"if url:kind() ~= 'sftp' then error('expected SFTP URL, got '..tostring(url:kind())) end","typeGuard":"fn is_sftp_url(url: &Url) -> bool {\n    matches!(url, Url::Sftp { .. })\n}","tryCatchPattern":"match SftpFile::new(url).await {\n    Err(e) if e.to_string().starts_with(\"Not a SFTP URL\") => {\n        return vfs::File::open(url).await; // generic dispatch by kind\n    }\n    r => r,\n}","preventionTips":["Route remote operations through the generic VFS layer instead of calling the SFTP engine directly","Preserve the original URL when joining/rewriting paths — don't rebuild a Url from a local Path","Check url kind before engine-specific calls at API boundaries","After upgrades, verify URL variant construction still matches the Sftp shape"],"tags":["sftp","url","invalid-input"],"backgroundTag":"invalid-url-variant","analyzedSha":"a541adde4e5b082719a0f21a87eb3eab071ece58","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}