{"record":{"id":"abd391bab44fd9c9","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-abd391","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/script_udf_support/src/transform_udf_script.rs","lineNumber":73,"sourceCode":"use self::venv::TempDir;\nuse super::runtime_pool::Pool;\nuse super::runtime_pool::RuntimeBuilder;\nuse crate::ScriptUdfFunctionDesc;\n\npub enum ScriptRuntime {\n    JavaScript(JsRuntimePool),\n    WebAssembly(arrow_udf_runtime::wasm::Runtime),\n    #[cfg(feature = \"python-udf\")]\n    Python(python_pool::PyRuntimePool),\n}\n\nstatic PY_VERSION: LazyLock<String> =\n    LazyLock::new(|| venv::detect_python_version().unwrap_or(\"3.12\".to_string()));\n\nimpl ScriptRuntime {\n    pub fn try_create(func: &ScriptUdfFunctionDesc, _temp_dir: Option<TempDir>) -> Result<Self> {\n        let UDFType::Script(box UDFScriptCode { language, code, .. }) = &func.udf_type else {\n            unreachable!()\n        };\n        match language {\n            UDFLanguage::JavaScript => {\n                let builder = JsRuntimeBuilder {\n                    name: func.name.clone(),\n                    handler: func.func_name.clone(),\n                    code: String::from_utf8(code.to_vec())?,\n                    output_type: func.data_type.as_ref().clone(),\n                    counter: Default::default(),\n                };\n                Ok(Self::JavaScript(JsRuntimePool::new(builder)))\n            }\n            UDFLanguage::WebAssembly => {\n                let start = std::time::Instant::now();\n                let runtime = arrow_udf_runtime::wasm::Runtime::new(code).map_err(|err| {\n                    ErrorCode::UDFRuntimeError(format!(\n                        \"Failed to create WASM runtime for module: {err}\"\n                    ))","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/script_udf_support/src/transform_udf_script.rs#L55-L91","documentation":"`unreachable!()` in `ScriptRuntime::try_create` (transform_udf_script.rs): the function destructures `func.udf_type` expecting the `UDFType::Script` variant and panics if a script UDF runtime is requested for a non-script (e.g. UDF/UDAF lambda) descriptor. It means `try_create` was called with a UDF description whose type is not `Script` — an internal dispatch bug rather than a user-configurable error.","triggerScenarios":"Registering or invoking a script UDF where the descriptor's `udf_type` is not `UDFType::Script` — e.g. the catalog resolved a UDF whose type is the default/other variant but routed it to the script runtime factory, or a corrupted/malformed UDF entry in the meta store.","commonSituations":"Mixed UDF deployments after a version upgrade changed `UDFType` variants, calling a server-defined UDF that was mistakenly classified as script, or meta store entries written by an older Databend version.","solutions":["Verify the UDF definition (`SHOW FUNCTIONS` / catalog entry) actually declares a script language (JavaScript) and re-create it if not.","Drop and re-create the UDF so its descriptor is written with the current `UDFType` format.","Upgrade/restart the cluster so query nodes and meta store agree on the UDF type enum.","If reproducible, file an issue with the `CREATE FUNCTION` statement and server version."],"exampleFix":"// before\nlet UDFType::Script(box UDFScriptCode { language, code, .. }) = &func.udf_type else {\n    unreachable!()\n};\n// after\nlet UDFType::Script(box UDFScriptCode { language, code, .. }) = &func.udf_type else {\n    return Err(ErrorCode::BadArguments(format!(\n        \"script runtime requested for non-script UDF: {}\", func.name\n    )));\n};","handlingStrategy":"validation","validationCode":"-- confirm the UDF is actually a script UDF before invoking\nSELECT func_name, language FROM system.functions WHERE name = 'my_udf'; -- expect language = 'JavaScript'","typeGuard":null,"tryCatchPattern":"// catch internal panic errors from UDF calls and fall back to re-creating the function\nif err.to_string().contains(\"entered unreachable code\") { drop_and_recreate_udf(name); }","preventionTips":["Re-create UDFs after major version upgrades so descriptors use current enum formats.","Keep all nodes on the same version as the meta store.","Validate UDF type/language at creation time.","Verify with system.functions before calling."],"tags":["rust","panic","udf","script","dispatch"],"backgroundTag":"internal-invariant-violation","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"}