sxyazi/yazi · error

Unknown copy type

Error message

Unknown copy type: {}

What it means

The `copy` command in Yazi's manager assembles copied text per selected file based on a copy type (`form.r#type`). Any type other than the recognized ones (e.g. "filename", "name_without_ext", plus built-ins like "path", "dirname", "url") hits the catch-all branch and bails with this message naming the offending type.

Solutions

  1. Check the copy type in the keymap/plugin call against Yazi's docs and fix the spelling (valid types: filename, name_without_ext, path, dirname, etc.).
  2. Upgrade/downgrade Yazi if the type was renamed between versions.
  3. If writing a plugin, extend the match in yazi-actor/src/mgr/copy.rs to handle the new type before using it.

Example fix

// before (keymap.toml)
{ on = [ "c", "n" ], run = "copy filenamee" }

// after
{ on = [ "c", "n" ], run = "copy filename" }
Defensive patterns

Strategy: validation

Validate before calling

local valid = { path = true, filename = true, name_without_ext = true, dirname = true }
local ok = valid[args.type]
if not ok then error("invalid copy type: " .. tostring(args.type)) end

Type guard

local function is_valid_copy_type(t)
  return t == "path" or t == "filename" or t == "name_without_ext" or t == "dirname"
end

Try / catch

local ok, err = pcall(function() Command("copy"):arg({ "--", form_type }):send() end)
if not ok then ya.notify({ title = "copy failed", content = err, level = "error" }) end

Prevention

When it happens

Trigger: Invoking the `copy` action/plugin with an unrecognized `type` value in its form, e.g. `plugin copy -- sync ...` with a misspelled or unsupported type string.

Common situations: Typo in a keymap command (e.g. `copy filenamee`); using a type removed or renamed in a newer Yazi version; custom plugin calling the manager copy API with an invalid type.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at yazi-actor/src/mgr/copy.rs:51

					s.extend_from_slice(&form.separator.transform(&f.url.to_strand()));
				}
				"dirpath" | "dirname" => {
					if let Some(p) = f.content_path().parent() {
						s.extend_from_slice(&form.separator.transform(&p));
					}
				}
				"dirurl" => {
					if let Some(p) = f.url.parent() {
						s.extend_from_slice(&form.separator.transform(&p.to_strand()));
					}
				}
				"filename" => {
					s.extend_from_slice(&form.separator.transform(&f.name().unwrap_or_default()));
				}
				"name_without_ext" => {
					s.extend_from_slice(&form.separator.transform(&f.stem().unwrap_or_default()));
				}
				_ => bail!("Unknown copy type: {}", form.r#type),
			};
			if it.peek().is_some() {
				s.push(b'\n');
			}
		}

		// Copy the CWD path regardless even if the directory is empty
		if s.is_empty() && matches!(&*form.r#type, "dirpath" | "dirname") {
			s.extend_from_slice(&form.separator.transform(&cx.current().content_path()));
		} else if s.is_empty() && form.r#type == "dirurl" {
			s.extend_from_slice(&form.separator.transform(&cx.cwd().to_strand()));
		}

		futures::executor::block_on(CLIPBOARD.set(s));
		succ!();
	}
}

View on GitHub (pinned to a541adde4e)