{"record":{"id":"35b614a7ab738ebc","repo":"BoundaryML/baml","slug":"undefined-function-name","errorCode":null,"errorMessage":"undefined function: {name}","messagePattern":"undefined function: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/codegen.rs","lineNumber":752,"sourceCode":"                        self.emit(store_instr);\n                    }\n                    _ => panic!(\"Invalid left hand of assignment, only variables, instance fields and array elements can be assigned\"),\n                }\n            }\n            thir::Statement::DeclareAndAssign {\n                name, value, watch, ..\n            } => {\n                self.compile_expression_with_block_behavior(value, true);\n                let local_index = self.track_local(name);\n                if let Some(spec) = watch {\n                    self.emit_string_literal(&spec.name); // This adds LoadConst\n\n                    match &spec.when {\n                        WatchWhen::FunctionName(fn_name) => {\n                            if let Some(&index) = self.globals.get(fn_name.name()) {\n                                self.emit(Instruction::LoadGlobal(index));\n                            } else {\n                                panic!(\"undefined function: {name}\");\n                            }\n                        }\n                        WatchWhen::Never => {}\n\n                        WatchWhen::Manual => {\n                            self.emit_string_literal(\"manual\");\n                        }\n\n                        WatchWhen::Auto => {\n                            let index = self.add_constant(Value::Null);\n                            self.emit(Instruction::LoadConst(index));\n                        }\n                    }\n\n                    self.emit(Instruction::Watch(local_index));\n                }\n            }\n            thir::Statement::Return { expr, .. } => {","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/codegen.rs#L734-L770","documentation":"A panic during codegen of a DeclareAndAssign with a watch clause: when the watch trigger is WatchWhen::FunctionName, the named function must exist in the compiler's globals map. The panic reports the variable name (not the function name), so the message text can be misleading — the actual lookup that failed is the watch function name.","triggerScenarios":"`watch` attribute referencing a function name that is not a registered global function; misspelled function in a watch clause.","commonSituations":"Renaming or deleting a watched function without updating watch clauses; typos in the watch target function name.","solutions":["Fix the function name in the watch clause to match a defined function","Define the referenced function before/where it is watched","Remove the watch clause if the trigger function is no longer needed"],"exampleFix":"// before\nlet v = expr watch MyFuntion\n// after\nlet v = expr watch MyFunction","handlingStrategy":"validation","validationCode":"fn validate_watch_fn(globals: &[&str], fn_name: &str) -> Result<(), String> {\n    if !globals.contains(&fn_name) {\n        return Err(format!(\"watch function '{}' is not defined\", fn_name));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reference only defined functions in watch clauses","Update all watch clauses when renaming functions","Keep watch targets and function definitions in sync via code review"],"tags":["rust","compiler","codegen","panic","watch"],"backgroundTag":"resource-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}