{"record":{"id":"e420941f5d11d54f","repo":"databendlabs/databend","slug":"failed-to-load-lua-util-functions","errorCode":null,"errorMessage":"Failed to load lua_util functions: {}","messagePattern":"Failed to load lua_util functions: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/control/src/lua_support.rs","lineNumber":496,"sourceCode":"    // `metactl.ZipfGenerator:new(num_keys, alpha)` directly.\n    let zipf_generator = lua\n        .load(ZIPF_LOAD_GENERATOR)\n        .eval::<Table>()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load zipf_load_generator: {}\", e))?;\n\n    metactl_table\n        .set(\"ZipfGenerator\", zipf_generator)\n        .map_err(|e| anyhow::anyhow!(\"Failed to register ZipfGenerator: {}\", e))?;\n\n    // Set the metactl table as a global\n    lua.globals()\n        .set(\"metactl\", metactl_table)\n        .map_err(|e| anyhow::anyhow!(\"Failed to register metactl namespace: {}\", e))?;\n\n    // Load lua_util functions (which registers to_string in metactl namespace)\n    lua.load(LUA_UTIL)\n        .exec()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load lua_util functions: {}\", e))?;\n\n    Ok(())\n}\n\npub fn new_grpc_client(\n    addresses: Vec<String>,\n) -> Result<Arc<ClientHandle<DatabendRuntime>>, CreationError> {\n    eprintln!(\n        \"Using gRPC API address: {}\",\n        serde_json::to_string(&addresses).unwrap()\n    );\n    MetaGrpcClient::try_create(\n        addresses,\n        \"root\",\n        \"xxx\",\n        Some(Duration::from_secs(2)),\n        Some(Duration::from_secs(1)),\n        None,","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/control/src/lua_support.rs#L478-L514","documentation":"Finally, `setup_lua_environment` executes the embedded `LUA_UTIL` Lua chunk, which defines utility functions such as `metactl.to_string`. This error wraps any failure of `lua.load(LUA_UTIL).exec()` — a compile (syntax) error in the embedded source or a runtime error while it executes.","triggerScenarios":"Running `lua.load(LUA_UTIL).exec()` during `setup_lua_environment` fails: the LUA_UTIL constant has a Lua syntax error, or its top-level statements raise a runtime error (e.g. indexing a missing `metactl` global, which would indicate the namespace registration above was skipped).","commonSituations":"After editing the LUA_UTIL constant and introducing a typo, running under an mlua Lua version that rejects syntax used in the chunk, or reordering setup so LUA_UTIL runs before the `metactl` global exists.","solutions":["Read the inner error text: syntax errors point at recent edits to the LUA_UTIL constant; runtime nil-index errors point at setup ordering.","Keep this `exec()` after the `metactl` global is registered, and have LUA_UTIL only assign into the existing table.","Verify the mlua Lua-version feature supports the syntax used in LUA_UTIL (e.g. integer division, goto).","Evaluate the chunk standalone with the same Lua version to locate the failing statement."],"exampleFix":"// before: util chunk assumes metactl exists\nto_string = function(v) ... end\n// after: assign into the existing namespace\nmetactl.to_string = function(v) ... end","handlingStrategy":"validation","validationCode":"// CI test: LUA_UTIL must exec cleanly and define metactl.to_string\nsetup_lua_environment(&lua)?;\nlet f: mlua::Function = lua.globals().get::<_, mlua::Table>(\"metactl\")?.get(\"to_string\")?;\nlet _ = f.call::<_, ()>(\"x\")?;","typeGuard":null,"tryCatchPattern":"match setup_lua_environment(&lua) {\n    Err(e) if e.to_string().contains(\"Failed to load lua_util functions\") => {\n        // embedded LUA_UTIL broken: surface inner Lua syntax/runtime error\n    }\n    other => other?,\n}","preventionTips":["Add a unit test that runs setup and asserts metactl.to_string exists and is callable.","Keep LUA_UTIL assigning into the pre-registered metactl table, never assuming fresh globals.","Check LUA_UTIL syntax against the mlua-selected Lua version on every edit.","Preserve setup ordering: metactl global registration must precede LUA_UTIL."],"tags":["lua","mlua","embedded-script","rust"],"backgroundTag":"module-init-failed","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}