{"record":{"id":"245ff060aeaa3a55","repo":"BoundaryML/baml","slug":"push-expects-exactly-one-argument-at","errorCode":null,"errorMessage":"push() expects exactly one argument at {:?}","messagePattern":"push\\(\\) expects exactly one argument at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2274,"sourceCode":"                        arg_vals.push(expect_value(\n                            evaluate_expr(\n                                arg,\n                                scopes,\n                                thir,\n                                run_llm_function,\n                                watch_handler,\n                                function_name,\n                            )\n                            .await?,\n                        )?);\n                    }\n\n                    // Mutate the array\n                    let mut receiver_val = receiver_cell.lock().unwrap();\n                    match &mut *receiver_val {\n                        BamlValueWithMeta::List(items, _) => {\n                            if arg_vals.len() != 1 {\n                                bail!(\"push() expects exactly one argument at {:?}\", meta.0);\n                            }\n                            items.push(arg_vals[0].clone());\n                            // Return void/unit\n                            EvalValue::Value(BamlValueWithMeta::Null(meta.clone()))\n                        }\n                        _ => bail!(\"push() can only be called on arrays at {:?}\", meta.0),\n                    }\n                } else {\n                    // Non-mutating methods\n                    let receiver_val = expect_value(\n                        evaluate_expr(\n                            receiver,\n                            scopes,\n                            thir,\n                            run_llm_function,\n                            watch_handler,\n                            function_name,\n                        )","sourceCodeStart":2256,"sourceCodeEnd":2292,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2256-L2292","documentation":"The interpreter enforces `push()` arity of exactly one argument: the value to append. This check happens at mutation time, inside the lock on the receiver cell, only after the receiver was confirmed to be an array variable.","triggerScenarios":"`arr.push()` with no arguments, or `arr.push(a, b)` with multiple arguments.","commonSituations":"Porting from languages whose push accepts varargs (e.g. Ruby or JS spread of multiple items); forgetting the argument when pushing a computed value.","solutions":["Pass exactly one argument to push","To append multiple items, call push once per item in a loop","Verify the argument expression evaluates successfully before the call"],"exampleFix":"// before\narr.push(a, b)\n// after\narr.push(a);\narr.push(b);","handlingStrategy":"validation","validationCode":"if (args.length !== 1) { throw new Error('push() expects exactly one argument'); }","typeGuard":null,"tryCatchPattern":"try { arr.push(...items); } catch (e) { if (String(e).includes('push() expects exactly one argument')) { items.forEach(i => arr.push(i)); } else { throw e; } }","preventionTips":["Call push with exactly one argument","Loop to append multiple items","Never rely on varargs semantics"],"tags":["runtime","arrays","arity","interpreter"],"backgroundTag":"missing-required-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}