sxyazi/yazi · error

Invalid new or old file name

Error message

Invalid new or old file name

What it means

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.

Solutions

  1. Sanitize the new names (ensure non-empty, valid UTF-8, no path separators) before invoking bulk_rename.
  2. Inspect the old files' names for non-UTF-8 bytes and fix them first.
  3. Test the rename mapping with a single entry to isolate the offending name.

Example fix

// before
{ from: "file\xFF", to: "" }
// after
{ from: "file", to: "renamed-file" }
Defensive patterns

Strategy: validation

Validate before calling

-- Lua, before bulk_rename
local function valid_name(n)
  return type(n) == "string" and #n > 0 and not n:find("[/\\0]") and utf8 and utf8.len(n) ~= nil
end
assert(valid_name(new_name), "new name must be a non-empty valid name")

Prevention

When it happens

Trigger: 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.

Common situations: Bulk rename input from external sources containing invalid bytes; empty replacement names from a regex substitution; filenames with invalid characters pasted from the clipboard.

Related errors


AI-assisted analysis of sxyazi/yazi@8ebf930f17 (2026-09-02). Data as JSON: /api/errors/a926b063b74722b0. Report an issue: GitHub.

Appendix: source

Thrown at yazi-actor/src/mgr/bulk_rename.rs:121

		}

		let (old, new) = old.into_iter().zip(new).filter(|(o, n)| o != n).unzip();
		let todo = Self::prioritized_paths(old, new);
		if todo.is_empty() {
			return Ok(());
		}

		if !Self::ask_continue(&todo, decision)? {
			return Ok(());
		}

		let permit = WATCHER.acquire().await.unwrap();
		let (mut failed, mut succeeded) = (Vec::new(), HashMap::with_capacity(todo.len()));
		for (o, n) in todo {
			let (Ok(old), Ok(new)) =
				(Self::replace_url(&selected[o.0], root, &o), Self::replace_url(&selected[n.0], root, &n))
			else {
				failed.push((o, n, anyhow!("Invalid new or old file name")));
				continue;
			};

			if maybe_exists(&new).await && !engine::must_identical(&old, &new).await {
				failed.push((o, n, anyhow!("Destination already exists")));
			} else if let Err(e) = engine::rename(&old, &new).await {
				failed.push((o, n, e.into()));
			} else if let Ok(f) = engine::file(new).await {
				succeeded.insert(old, f);
			} else {
				failed.push((o, n, anyhow!("Failed to retrieve file info")));
			}
		}

		if !succeeded.is_empty() {
			let it = succeeded.iter().map(|(o, n)| (o.as_url(), n.url.as_url()));
			log_if_err!(Pubsub::pub_after_bulk_rename(it));
			FilesOp::rename(succeeded);

View on GitHub (pinned to 8ebf930f17)