{"record":{"id":"7579f296f3887eb6","repo":"sxyazi/yazi","slug":"due-to-cargo-s-limitations-yazi-on-crates-io-must","errorCode":null,"errorMessage":"Due to Cargo's limitations, Yazi on crates.io must be built with `cargo install --force yazi-build`","messagePattern":"Due to Cargo's limitations, Yazi on crates\\.io must be built with `cargo install --force yazi-build`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-cli/build.rs","lineNumber":14,"sourceCode":"#[path = \"src/args.rs\"]\nmod args;\n\nuse std::{env, error::Error};\n\nuse clap::CommandFactory;\nuse clap_complete::{Shell, generate_to};\n\nfn main() -> Result<(), Box<dyn Error>> {\n\tlet manifest = env::var_os(\"CARGO_MANIFEST_DIR\").unwrap().to_string_lossy().replace(r\"\\\", \"/\");\n\tif manifest.contains(\"/git/checkouts/yazi-\")\n\t\t|| manifest.contains(\"/registry/src/index.crates.io-\")\n\t{\n\t\tpanic!(\n\t\t\t\"Due to Cargo's limitations, Yazi on crates.io must be built with `cargo install --force yazi-build`\"\n\t\t);\n\t}\n\n\tgenerate()\n}\n\nfn generate() -> Result<(), Box<dyn Error>> {\n\tif env::var_os(\"YAZI_GEN_COMPLETIONS\").is_none() {\n\t\treturn Ok(());\n\t}\n\n\tlet cmd = &mut args::Args::command();\n\tlet bin = \"ya\";\n\tlet out = \"completions\";\n\n\tstd::fs::create_dir_all(out)?;\n\tfor sh in [Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/sxyazi/yazi/blob/441b332de8b8800e70784cfbfb75369ab51ed9dd/yazi-cli/build.rs#L1-L32","documentation":"Thrown by the impl_into_integer! macro in yazi-shared (yazi-shared/src/data/macros.rs:46) when a Data value is converted to an integer type via TryFrom but its variant is not convertible. Only Data::Integer, Data::Number (whole-valued, in-range floats via float_to_i64), Data::String (parseable), and Data::Id are accepted; any other variant (Bool, Nil, List, Table, Function, etc.) bails with this message. It is the yazi event/plugin bridge's equivalent of a type error: the argument exists but has the wrong shape.","triggerScenarios":"Calling an event/command handler or plugin API that does `action.get::<u8>(...)` / `take::<usize>(...)` while the Lua side passed a boolean, nil, table, or list for that argument; also strings that fail integer parse produce a different error, but booleans and nil hit exactly this bail. Typical examples: passing `true` instead of `1` for a count/ration, or forgetting an optional argument so nil is delivered.","commonSituations":"Keymap or plugin config values with wrong types after a yazi upgrade changed an argument's expected type; plugin authors calling ya.emit() with a Lua table where a number is expected; nil leaking through from an unset config option.","solutions":["Check the Lua call site and pass an actual integer (or a numeric string) for the argument named in the surrounding command","Guard optional values before emitting: only include the argument when it is non-nil","Inspect the delivered Data with ya.dbg()/tracing (YAZI_LOG=debug) to see which variant arrived","If the argument may legitimately be absent, handle it in Rust with get()/str()/bool() defaults or with_opt on the sender side instead of requiring TryFrom"],"exampleFix":"-- before\nya.emit(\"resize\", { ratio = true })\n-- after\nya.emit(\"resize\", { ratio = 1 })","handlingStrategy":"validation","validationCode":"-- Lua: validate before emitting\nlocal function to_int(v)\n  local n = tonumber(v)\n  assert(n and math.floor(n) == n and math.type(n) == \"integer\", \"expected an integer\")\n  return n\nend\nya.emit(\"resize\", { ratio = to_int(ratio) })","typeGuard":"-- Lua\nlocal function is_int_like(v)\n  local n = tonumber(v)\n  return n ~= nil and math.floor(n) == n and n == n\nend","tryCatchPattern":"-- Lua: catch emit/handler errors\nlocal ok, err = pcall(ya.emit, \"resize\", { ratio = v })\nif not ok then ya.dbg(tostring(err)) end","preventionTips":["Always coerce with tonumber()/math.floor before passing numeric arguments","Assert required argument types in plugin entry points","Keep plugin and yazi versions aligned so argument contracts match","Use ya.dbg() during development to dump emitted argument tables"],"tags":["rust","lua","type-conversion","plugin-api","yazi"],"backgroundTag":"type-conversion-failed","analyzedSha":"441b332de8b8800e70784cfbfb75369ab51ed9dd","analyzedAt":"2026-08-19T05:27:26.468Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}