{"record":{"id":"a926b063b74722b0","repo":"sxyazi/yazi","slug":"invalid-new-or-old-file-name","errorCode":null,"errorMessage":"Invalid new or old file name","messagePattern":"Invalid new or old file name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-actor/src/mgr/bulk_rename.rs","lineNumber":121,"sourceCode":"\t\t}\n\n\t\tlet (old, new) = old.into_iter().zip(new).filter(|(o, n)| o != n).unzip();\n\t\tlet todo = Self::prioritized_paths(old, new);\n\t\tif todo.is_empty() {\n\t\t\treturn Ok(());\n\t\t}\n\n\t\tif !Self::ask_continue(&todo, decision)? {\n\t\t\treturn Ok(());\n\t\t}\n\n\t\tlet permit = WATCHER.acquire().await.unwrap();\n\t\tlet (mut failed, mut succeeded) = (Vec::new(), HashMap::with_capacity(todo.len()));\n\t\tfor (o, n) in todo {\n\t\t\tlet (Ok(old), Ok(new)) =\n\t\t\t\t(Self::replace_url(&selected[o.0], root, &o), Self::replace_url(&selected[n.0], root, &n))\n\t\t\telse {\n\t\t\t\tfailed.push((o, n, anyhow!(\"Invalid new or old file name\")));\n\t\t\t\tcontinue;\n\t\t\t};\n\n\t\t\tif maybe_exists(&new).await && !engine::must_identical(&old, &new).await {\n\t\t\t\tfailed.push((o, n, anyhow!(\"Destination already exists\")));\n\t\t\t} else if let Err(e) = engine::rename(&old, &new).await {\n\t\t\t\tfailed.push((o, n, e.into()));\n\t\t\t} else if let Ok(f) = engine::file(new).await {\n\t\t\t\tsucceeded.insert(old, f);\n\t\t\t} else {\n\t\t\t\tfailed.push((o, n, anyhow!(\"Failed to retrieve file info\")));\n\t\t\t}\n\t\t}\n\n\t\tif !succeeded.is_empty() {\n\t\t\tlet it = succeeded.iter().map(|(o, n)| (o.as_url(), n.url.as_url()));\n\t\t\tlog_if_err!(Pubsub::pub_after_bulk_rename(it));\n\t\t\tFilesOp::rename(succeeded);","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/sxyazi/yazi/blob/8ebf930f1796ae2076b7d6b0c5e93a1002c18134/yazi-actor/src/mgr/bulk_rename.rs#L103-L139","documentation":"In bulk_rename r#do, each old/new (Optimizely-style) entry is turned into full URLs via replace_url, which requires valid UTF-8/naming. If either conversion fails, the pair is recorded as failed with \"Invalid new or old file name\" and the batch continues with the rest.","triggerScenarios":"replace_url returns Err for either the old or the new name — e.g. non-UTF-8 text, empty name, or a name that violates URL/path construction rules.","commonSituations":"Bulk rename input from external sources containing invalid bytes; empty replacement names from a regex substitution; filenames with invalid characters pasted from the clipboard.","solutions":["Sanitize the new names (ensure non-empty, valid UTF-8, no path separators) before invoking bulk_rename.","Inspect the old files' names for non-UTF-8 bytes and fix them first.","Test the rename mapping with a single entry to isolate the offending name."],"exampleFix":"// before\n{ from: \"file\\xFF\", to: \"\" }\n// after\n{ from: \"file\", to: \"renamed-file\" }","handlingStrategy":"validation","validationCode":"-- Lua, before bulk_rename\nlocal function valid_name(n)\n  return type(n) == \"string\" and #n > 0 and not n:find(\"[/\\\\0]\") and utf8 and utf8.len(n) ~= nil\nend\nassert(valid_name(new_name), \"new name must be a non-empty valid name\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanitize regex-substitution output (drop empty results).","Reject names with path separators or NUL bytes.","Verify UTF-8 validity of names sourced from external data."],"tags":["rename","validation","filename"],"backgroundTag":"invalid-filename","analyzedSha":"8ebf930f1796ae2076b7d6b0c5e93a1002c18134","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}