sxyazi/yazi · error

Invalid 'opt' in DisplaceDoForm

Error message

Invalid 'opt' in DisplaceDoForm

What it means

DisplaceDoForm carries the options for the internal mgr 'displace-do' action. Its TryFrom<ActionCow> implementation requires an 'opt' entry; when a.take_any("opt") yields None the error "Invalid 'opt' in DisplaceDoForm" is thrown. The *_do actions are internal follow-ups triggered by confirmation forms, so the missing payload indicates a malformed internal dispatch.

Solutions

  1. Attach the DisplaceOpt payload under 'opt' when constructing the displace-do action.
  2. Dispatch the action through mgr's normal confirm path instead of hand-building ActionCow.
  3. Check the yazi version's mgr/displace_do.rs for the exact Opt struct and field names.
  4. Rebuild/update any patched or third-party plugin that emits this action.

Example fix

// before
let a = ActionCow::from("mgr.displace-do");
let form = DisplaceDoForm::try_from(a)?; // Invalid 'opt' in DisplaceDoForm
// after
let a = ActionCow::from(("mgr.displace-do", DisplaceOpt::default()));
let form = DisplaceDoForm::try_from(a)?;
Defensive patterns

Strategy: validation

Validate before calling

if !action.has("opt") {
    anyhow::bail!("mgr.displace-do requires DisplaceOpt under 'opt'");
}
let form = DisplaceDoForm::try_from(action)?;

Type guard

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

Try / catch

let form = DisplaceDoForm::try_from(action)
    .with_context(|| format!("displace-do malformed: {e:#}"))?;

Prevention

When it happens

Trigger: Dispatching mgr.displace-do without the typed Opt payload, or with an 'opt' whose stored type does not match DisplaceOpt so take_any fails.

Common situations: Custom code re-emitting the displace confirmation action manually; interrupted/miswired internal flow after a yazi upgrade changed how displace-do options are packaged.

Related errors


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

Appendix: source

Thrown at yazi-parser/src/mgr/displace_do.rs:15

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

#[derive(Clone, Debug)]
pub struct DisplaceDoForm {
	pub opt: DisplaceOpt,
}

impl TryFrom<ActionCow> for DisplaceDoForm {
	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 DisplaceDoForm"))? })
	}
}

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

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

View on GitHub (pinned to 5f901b886b)