{"record":{"id":"e238f6b5d4ce185c","repo":"databendlabs/databend","slug":"function-factory-must-be-set-before-registering","errorCode":null,"errorMessage":"function factory must be set before registering","messagePattern":"function factory must be set before registering","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/expression/src/function/function_builder.rs","lineNumber":238,"sourceCode":"            })\n            .map(|builder| Arc::new(builder.finish()))\n        })));\n        self\n    }\n\n    pub fn register(self) -> &'a mut FunctionRegistry {\n        let FunctionBuilder {\n            registry,\n            name,\n            property,\n            aliases,\n            additional_cast_rules,\n            dynamic_cast_rules,\n            factory,\n            ..\n        } = self;\n\n        let factory = factory.expect(\"function factory must be set before registering\");\n\n        registry.register_function_factory(&name, factory);\n\n        Self::register_common(\n            registry,\n            &name,\n            property,\n            aliases,\n            additional_cast_rules,\n            dynamic_cast_rules,\n        );\n\n        registry\n    }\n}\n\npub struct InlineFunctionBuilder {\n    name: String,","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/expression/src/function/function_builder.rs#L220-L256","documentation":"This panic occurs in `FunctionRegistryBuilder::register` when the builder's optional `factory` field is `None`. The function factory must be installed (via the builder's factory-setting API) before `register` is called, because registration delegates function resolution to the factory. The library intentionally panics via `expect` since this is a programmer/API-usage error, not a runtime condition.","triggerScenarios":"Calling `FunctionRegistryBuilder::register(name, ...)` on a builder that was never given a function factory — i.e., skipping the factory assignment step (e.g. `with_factory` / the `factory` builder field) before calling `register`.","commonSituations":"Hand-rolling a registry builder instead of using the standard helper macros; refactoring that moves or deletes the factory setup call; constructing a builder with struct-update syntax (`..Default::default()`) that leaves `factory` as None.","solutions":["Set the function factory on the builder before calling `register` (e.g. assign the `factory` field or call the builder's factory-setting method).","Prefer the existing function-registration macros/helpers in the crate, which wire the factory automatically.","Audit custom builder construction paths for `..Default::default()` that silently reset `factory` to None."],"exampleFix":"// before\nlet builder = FunctionRegistryBuilder { name, ..Default::default() };\nbuilder.register(registry);\n// after\nlet builder = FunctionRegistryBuilder { name, factory: Some(Box::new(MyFactory)), ..Default::default() };\nbuilder.register(registry);","handlingStrategy":"type-guard","validationCode":"assert!(builder.factory.is_some(), \"factory must be set before register\");","typeGuard":"fn factory_is_set(b: &FunctionRegistryBuilder) -> bool { b.factory.is_some() }","tryCatchPattern":"// Rust panics are not catchable idiomaticly here; guard instead:\nif !factory_is_set(&builder) { return Err(ErrorCode::Internal(\"factory not set\")); }","preventionTips":["Always construct registry builders through the provided macros/helpers.","Avoid `..Default::default()` struct-update syntax that can reset required fields.","Add a debug_assert for factory presence in custom registration paths."],"tags":["rust","function-registry","builder-pattern"],"backgroundTag":"missing-required-config-field","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"}