sxyazi/yazi · error

Invalid 'token' in ShowForm

Error message

Invalid 'token' in ShowForm

What it means

`ShowForm::try_from` also requires a `"token"` key, extracted after cfg. The token correlates the shown dialog with the pending confirmation request; without it the form cannot be built and this error is raised.

Source

Thrown at yazi-parser/src/confirm/show.rs:21

use yazi_config::popup::ConfirmCfg;
use yazi_shared::{CompletionToken, event::ActionCow};

#[derive(Debug)]
pub struct ShowForm {
	pub cfg:   ConfirmCfg,
	pub token: CompletionToken,
}

impl TryFrom<ActionCow> for ShowForm {
	type Error = anyhow::Error;

	fn try_from(mut a: ActionCow) -> Result<Self, Self::Error> {
		let Some(cfg) = a.take_any("cfg") else {
			bail!("Invalid 'cfg' in ShowForm");
		};

		let Some(token) = a.take_any("token") else {
			bail!("Invalid 'token' in ShowForm");
		};

		Ok(Self { cfg, token })
	}
}

impl From<Box<Self>> for ShowForm {
	fn from(value: Box<Self>) -> Self { *value }
}

impl FromLua for ShowForm {
	fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
}

impl IntoLua for ShowForm {
	fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
}

View on GitHub (pinned to 5f901b886b)

Solutions

  1. Include the `"token"` value (the confirmation request token) in the action payload.
  2. Ensure the token was obtained from the confirm plugin's request step and passed through unchanged.
  3. Check for key spelling/type mismatches when building the ActionCow.

Example fix

-- before (Lua)
ya.manager_emit("plugin", { "confirm", args = { "show", cfg = my_cfg } })
-- after
ya.manager_emit("plugin", { "confirm", args = { "show", cfg = my_cfg, token = tok } })
Defensive patterns

Strategy: validation

Validate before calling

assert!(action.get("cfg").is_some() && action.get("token").is_some(),
        "confirm:show requires both 'cfg' and 'token'");

Type guard

fn is_valid_show_action(a: &Action) -> bool {
    a.get("cfg").is_some() && a.get("token").is_some()
}

Try / catch

match ShowForm::try_from(action) {
    Ok(form) => show(form),
    Err(e) if e.to_string().contains("Invalid 'token'") => {
        eprintln!("confirm:show missing 'token': {e}")
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Emitting `confirm:show` with cfg present but no `"token"` entry, or the token stored under a different key/type so `take_any("token")` yields None.

Common situations: Plugin code that forwards cfg but forgets the request token; manually constructing the action in scripts/IPC; key renamed in a yazi update.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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