{"record":{"id":"fe1ac9365cc31de3","repo":"sxyazi/yazi","slug":"linemode-must-be-between-1-and-20-characters-long","errorCode":null,"errorMessage":"Linemode must be between 1 and 20 characters long","messagePattern":"Linemode must be between 1 and 20 characters long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-parser/src/mgr/linemode.rs","lineNumber":19,"sourceCode":"use anyhow::bail;\nuse mlua::{ExternalError, FromLua, IntoLua, Lua, Value};\nuse serde::Deserialize;\nuse yazi_shared::event::ActionCow;\n\n#[derive(Debug, Deserialize)]\npub struct LinemodeForm {\n\t#[serde(alias = \"0\")]\n\tpub new: String,\n}\n\nimpl TryFrom<ActionCow> for LinemodeForm {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(a: ActionCow) -> Result<Self, Self::Error> {\n\t\tlet me: Self = a.deserialize()?;\n\n\t\tif me.new.is_empty() || me.new.len() > 20 {\n\t\t\tbail!(\"Linemode must be between 1 and 20 characters long\");\n\t\t}\n\n\t\tOk(me)\n\t}\n}\n\nimpl FromLua for LinemodeForm {\n\tfn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err(\"unsupported\".into_lua_err()) }\n}\n\nimpl IntoLua for LinemodeForm {\n\tfn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err(\"unsupported\".into_lua_err()) }\n}\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-parser/src/mgr/linemode.rs#L1-L33","documentation":"The `linemode` action deserializes into its form, then validates that the new linemode string is 1–20 characters long; empty or longer strings bail with this message. It guards against nonsensical or oversized linemode labels being applied to the manager UI.","triggerScenarios":"Calling the `mgr:linemode` action with `new` = \"\" or a string longer than 20 characters (length measured in bytes via `str::len`).","commonSituations":"Keymap/config or Lua plugin passing an empty linemode after a failed lookup; long custom linemode names exceeding 20 bytes; multi-byte UTF-8 names where byte length exceeds 20 despite few characters.","solutions":["Pass a linemode name between 1 and 20 bytes.","Trim or truncate the custom linemode label before emitting the action.","If using a multibyte label, keep total byte length ≤ 20 (e.g. slice on char boundaries)."],"exampleFix":"-- before (Lua)\nya.manager_emit(\"linemode\", { mode }) -- mode may be \"\"\n-- after\nif mode ~= nil and #mode > 0 and #mode <= 20 then\n  ya.manager_emit(\"linemode\", { mode })\nend","handlingStrategy":"validation","validationCode":"assert!(!new.is_empty() && new.len() <= 20, \"linemode name must be 1..=20 bytes\");","typeGuard":"fn is_valid_linemode(s: &str) -> bool {\n    !s.is_empty() && s.len() <= 20\n}","tryCatchPattern":"match LinemodeForm::try_from(action) {\n    Ok(form) => apply(form),\n    Err(e) if e.to_string().contains(\"Linemode must be between\") => {\n        eprintln!(\"linemode name out of range: {e}\")\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Truncate or trim custom linemode names to ≤20 bytes before emitting.","Remember the limit is bytes, not chars — multibyte labels count more.","Handle empty lookups (mode == nil/\"\") by skipping the emit."],"tags":["parser","linemode","length-validation","config"],"backgroundTag":"string-length-out-of-range","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}