{"record":{"id":"95f3418cea02221a","repo":"databendlabs/databend","slug":"lua-execution-error-95f341","errorCode":null,"errorMessage":"Lua execution error: {}","messagePattern":"Lua execution error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/control/src/lua_support.rs","lineNumber":533,"sourceCode":"        DEFAULT_GRPC_MESSAGE_SIZE,\n    )\n}\n\npub fn new_admin_client(addr: &str) -> MetaAdminClient {\n    MetaAdminClient::new(addr)\n}\n\npub async fn run_lua_script(script: &str) -> anyhow::Result<()> {\n    let lua = Lua::new();\n\n    setup_lua_environment(&lua)?;\n\n    #[allow(clippy::disallowed_types)]\n    let local = tokio::task::LocalSet::new();\n    let res = local.run_until(lua.load(script).exec_async()).await;\n\n    if let Err(e) = res {\n        return Err(anyhow::anyhow!(\"Lua execution error: {}\", e));\n    }\n    Ok(())\n}\n\npub async fn run_lua_script_with_result(\n    script: &str,\n) -> anyhow::Result<Result<Option<String>, String>> {\n    let lua = Lua::new();\n\n    setup_lua_environment(&lua)?;\n\n    #[allow(clippy::disallowed_types)]\n    let local = tokio::task::LocalSet::new();\n    let res = local\n        .run_until(lua.load(script).eval_async::<mlua::MultiValue>())\n        .await;\n\n    match res {","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/control/src/lua_support.rs#L515-L551","documentation":"run_lua_script executes a Lua script on an mlua async runtime. If `lua.load(script).exec_async()` returns Err — a syntax error, a runtime error raised by the script (via `error()`), or a callback error — the function wraps it in anyhow with \"Lua execution error: {}\". This is a pass-through wrapper: the real cause is in the inner Lua error message.","triggerScenarios":"Calling run_lua_script(script) where the script fails to compile (syntax error), calls error()/panic, references a nil global, or a Rust-registered function it calls returns an error.","commonSituations":"Meta-service Lua maintenance/upgrade scripts edited by hand with typos; scripts assuming tables or APIs that don't exist in the embedded runtime; scripts that raise errors on unexpected meta data state.","solutions":["Read the inner Lua error after 'Lua execution error:' to find the failing line/function in the script","Validate the script syntax with a standalone lua interpreter (luac -p) before running it against meta","Fix the nil reference or error() call inside the Lua script","If a Rust callback is the cause, fix that function's error condition"],"exampleFix":"// before: run script directly and get opaque failure\nrun_lua_script(&script).await?;\n// after: smoke-test compile first (in a test)\nlet lua = mlua::Lua::new();\nlua.load(&script).exec_async().await\n    .expect(\"script must compile and run\");","handlingStrategy":"try-catch","validationCode":"if let Err(e) = luac_check(&script) { bail!(\"script will not compile: {e}\"); }","typeGuard":"fn is_compilable_lua(script: &str) -> bool { luac_syntax_check(script).is_ok() }","tryCatchPattern":"match run_lua_script(&script).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Lua execution error\") => log::error!(\"lua script failed: {e:#}\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Lint Lua scripts with luac -p before deploying","Keep a test harness that executes every maintenance script against a test meta","Avoid top-level error(); return errors as values"],"tags":["lua","meta-service","script-execution"],"backgroundTag":"invalid-argument-value","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}