sxyazi/yazi · error

Invalid 'opt' in ShowForm

Error message

Invalid 'opt' in ShowForm

What it means

ShowForm (the form payload for the cmp plugin's 'show' action) is built via TryFrom<ActionCow>, which requires the action to carry a payload under the key 'opt' that deserializes to the expected option type. When a.take_any("opt") returns None — the field is absent or of a type that cannot be taken as the target type — the anyhow! error "Invalid 'opt' in ShowForm" is raised. This guards internal action dispatch: the 'show' action must be dispatched programmatically with its typed options attached, not constructed ad-hoc.

Solutions

  1. Attach the typed options payload under the key 'opt' when constructing the show action, e.g. via the action's builder/with() API with the cmp show Opt struct.
  2. Ensure the value stored under 'opt' is exactly the expected Opt type for this ShowForm version; re-check the yazi version's cmp show options struct.
  3. If emitting from Lua, use the supported emit path so Rust-side options are serialized into the action rather than building a bare ActionCow.
  4. Update any custom plugin/patch code that created the action to match the current yazi-parser API (field names/shape may have changed).

Example fix

// before
let a = ActionCow::from("cmp.show");
let form = ShowForm::try_from(a)?; // Invalid 'opt' in ShowForm
// after
let a = ActionCow::from(("cmp.show", ShowOpt { /* fields */ }));
let form = ShowForm::try_from(a)?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: check before TryFrom
if !action.has("opt") {
    anyhow::bail!("cmp.show requires an 'opt' payload");
}
let form = ShowForm::try_from(action)?;

Type guard

fn has_opt(a: &ActionCow) -> bool { a.has("opt") }

Try / catch

match ShowForm::try_from(action) {
    Ok(form) => handle(form),
    Err(e) => tracing::error!("cmp.show action malformed: {e:#}"),
}

Prevention

When it happens

Trigger: Dispatching an ActionCow for cmp.show without an 'opt' field (a.take_any("opt") = None), or with an 'opt' value whose type does not match the struct's Opt field so take_any fails to downcast/convert it.

Common situations: Plugin or keymap code constructing the cmp show action manually and forgetting the payload; a version change renamed or restructured the options payload so older emitters no longer attach 'opt'; sending the action through a path that strips extra fields.

Related errors


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

Appendix: source

Thrown at yazi-parser/src/cmp/show.rs:19

use anyhow::anyhow;
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
use yazi_core::cmp::CmpOpt;
use yazi_shared::event::ActionCow;

#[derive(Clone, Debug)]
pub struct ShowForm {
	pub opt: CmpOpt,
}

impl From<CmpOpt> for ShowForm {
	fn from(opt: CmpOpt) -> Self { Self { opt } }
}

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

	fn try_from(mut a: ActionCow) -> Result<Self, Self::Error> {
		Ok(Self { opt: a.take_any("opt").ok_or_else(|| anyhow!("Invalid 'opt' in ShowForm"))? })
	}
}

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)