databendlabs/databend · error
internal error: entered unreachable code
Error message
internal error: entered unreachable code
What it means
`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.
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.
Example fix
// before
let UDFType::Script(box UDFScriptCode { language, code, .. }) = &func.udf_type else {
unreachable!()
};
// after
let UDFType::Script(box UDFScriptCode { language, code, .. }) = &func.udf_type else {
return Err(ErrorCode::BadArguments(format!(
"script runtime requested for non-script UDF: {}", func.name
)));
}; Defensive patterns
Strategy: validation
Validate before calling
-- confirm the UDF is actually a script UDF before invoking SELECT func_name, language FROM system.functions WHERE name = 'my_udf'; -- expect language = 'JavaScript'
Try / catch
// catch internal panic errors from UDF calls and fall back to re-creating the function
if err.to_string().contains("entered unreachable code") { drop_and_recreate_udf(name); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11).
Data as JSON: /api/errors/abd391bab44fd9c9.
Report an issue: GitHub.
Appendix: source
Thrown at src/query/script_udf_support/src/transform_udf_script.rs:73
use self::venv::TempDir;
use super::runtime_pool::Pool;
use super::runtime_pool::RuntimeBuilder;
use crate::ScriptUdfFunctionDesc;
pub enum ScriptRuntime {
JavaScript(JsRuntimePool),
WebAssembly(arrow_udf_runtime::wasm::Runtime),
#[cfg(feature = "python-udf")]
Python(python_pool::PyRuntimePool),
}
static PY_VERSION: LazyLock<String> =
LazyLock::new(|| venv::detect_python_version().unwrap_or("3.12".to_string()));
impl ScriptRuntime {
pub fn try_create(func: &ScriptUdfFunctionDesc, _temp_dir: Option<TempDir>) -> Result<Self> {
let UDFType::Script(box UDFScriptCode { language, code, .. }) = &func.udf_type else {
unreachable!()
};
match language {
UDFLanguage::JavaScript => {
let builder = JsRuntimeBuilder {
name: func.name.clone(),
handler: func.func_name.clone(),
code: String::from_utf8(code.to_vec())?,
output_type: func.data_type.as_ref().clone(),
counter: Default::default(),
};
Ok(Self::JavaScript(JsRuntimePool::new(builder)))
}
UDFLanguage::WebAssembly => {
let start = std::time::Instant::now();
let runtime = arrow_udf_runtime::wasm::Runtime::new(code).map_err(|err| {
ErrorCode::UDFRuntimeError(format!(
"Failed to create WASM runtime for module: {err}"
))View on GitHub (pinned to 288d84d76e)