{"record":{"id":"9f10368508b855ec","repo":"sxyazi/yazi","slug":"cannot-create-file-at-root","errorCode":null,"errorMessage":"Cannot create file at root","messagePattern":"Cannot create file at root","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-actor/src/mgr/create.rs","lineNumber":74,"sourceCode":"\nimpl Create {\n\tasync fn r#do(new: UrlBuf, dir: bool) -> Result<()> {\n\t\tlet _permit = WATCHER.acquire().await.unwrap();\n\n\t\tif dir {\n\t\t\tengine::create_dir_all(&new).await?;\n\t\t} else if let Ok(real) = engine::casefold(&new).await\n\t\t\t&& let Some((trail, key)) = real.pair()\n\t\t{\n\t\t\tok_or_not_found!(engine::remove_file(&new).await);\n\t\t\tFilesOp::Deleting(trail.into(), [key.into()].into()).emit();\n\t\t\tengine::create(&new).await?;\n\t\t} else if let Some(parent) = new.parent() {\n\t\t\tengine::create_dir_all(parent).await.ok();\n\t\t\tok_or_not_found!(engine::remove_file(&new).await);\n\t\t\tengine::create(&new).await?;\n\t\t} else {\n\t\t\tbail!(\"Cannot create file at root\");\n\t\t}\n\n\t\tif let Ok(real) = engine::casefold(&new).await\n\t\t\t&& let Some((trail, key)) = real.pair()\n\t\t{\n\t\t\tlet file = engine::file(&real).await?;\n\t\t\tFilesOp::Upserting(trail.into(), [(key.into(), file)].into()).emit();\n\t\t\tMgrProxy::reveal(&real);\n\t\t}\n\n\t\tOk(())\n\t}\n}\n","sourceCodeStart":56,"sourceCodeEnd":88,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-actor/src/mgr/create.rs#L56-L88","documentation":"Yazi's file-creation actor refuses to create a regular file when the requested URL has no parent directory, i.e. the target is the virtual root of a URL scheme. Creating a file requires a parent to exist (and possibly a stale file to be removed), so an anchorless path is treated as an invalid destination rather than attempted. It is thrown via `bail!` inside `mgr:create`'s `r#do` implementation.","triggerScenarios":"Calling `mgr:create` (the `create` plugin/command) with a target URL whose `parent()` is None — for example an empty path or a bare scheme root like `/` or `sftp://host/` — so the code falls into the final `else` branch.","commonSituations":"A user runs `:create` while in the root directory of a mount/scheme and yazi resolves the new file path to the root itself; custom plugins or keymaps that pass a computed URL to `mgr:create` without ensuring a filename component exists; misconfigured plugin snippets that join segments incorrectly.","solutions":["Ensure the target URL includes a filename component after the root (e.g. `/file.txt`, not `/`)","Check the parent with `url.parent()` before invoking `mgr:create` and bail with your own message if None","If creating at a scheme root is genuinely needed, pick a concrete parent directory first or use a different API that supports directory creation","Inspect any custom plugin/keymap that computes the create target and fix the path join logic"],"exampleFix":"// before\nact!(mgr:create, cx, url)  // url == \"/\" -> bails\n// after\nif url.parent().is_none() {\n    anyhow::bail!(\"provide a file name, not a scheme root\");\n}\nact!(mgr:create, cx, url)","handlingStrategy":"validation","validationCode":"fn can_create_at(url: &Url) -> bool {\n    url.parent().is_some()\n}\n// call only if can_create_at(&target) else surface a user message","typeGuard":"fn has_parent(url: &Url) -> bool {\n    url.parent().is_some()\n}","tryCatchPattern":"match mgr_create(cx, url).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Cannot create file at root\") => {\n        notify::warn(\"Pick a real directory, not the scheme root\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always join a filename onto a directory URL before calling create","Guard with url.parent().is_some() in plugin code","Never hardcode scheme-root targets like \"/\" in keymaps"],"tags":["filesystem","path-validation","yazi"],"backgroundTag":"missing-path-parent","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}