{"record":{"id":"f5a16d88516aa0fa","repo":"BoundaryML/baml","slug":"push-can-only-be-called-on-arrays-at","errorCode":null,"errorMessage":"push() can only be called on arrays at {:?}","messagePattern":"push\\(\\) can only be called on arrays at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2280,"sourceCode":"                                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                        )\n                        .await?,\n                    )?;\n\n                    // Evaluate arguments\n                    let mut arg_vals: Vec<BamlValueWithMeta<ExprMetadata>> =\n                        Vec::with_capacity(args.len());","sourceCodeStart":2262,"sourceCodeEnd":2298,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2262-L2298","documentation":"`push()` is only valid on array (List) values. When the receiver variable holds any other type — string, int, map/class, null — the interpreter's match on the cell contents falls through to this bail arm.","triggerScenarios":"Calling `push` on a variable whose runtime value is not a List: a class instance, a string, a number, or null (e.g. an uninitialized or wrongly-typed variable).","commonSituations":"A variable declared or inferred as something other than an array (often null from a failed parse or an LLM response) then used with push; confusing maps/objects with arrays when porting JS habits.","solutions":["Ensure the receiver is initialized as an array before pushing: `let arr = [];`","Check the variable's actual runtime type/value before calling push","If pushing key/value data, use a map/class with appropriate operations instead","Trace where the variable is assigned; a null from an upstream call is a common root cause"],"exampleFix":"// before\nlet arr;        // ends up null\narr.push(x)\n// after\nlet arr = [];\narr.push(x);","handlingStrategy":"type-guard","validationCode":"// verify the receiver holds an array before push\nif (!Array.isArray(receiver) || receiver == null) { throw new Error('push receiver must be an array'); }","typeGuard":"function isBamlList(v) { return v != null && v.__baml_type === 'List'; }","tryCatchPattern":"try { arr.push(x); } catch (e) { if (String(e).includes('push() can only be called on arrays')) { /* initialize as array or fix upstream type */ } else { throw e; } }","preventionTips":["Initialize arrays with `let arr = [];` before pushing","Validate types of values coming from LLM output before array operations","Check that assignments to the variable preserve array type"],"tags":["runtime","arrays","type-check","interpreter"],"backgroundTag":"type-mismatch","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"}