BoundaryML/baml · error
push() expects exactly one argument at
Error message
push() expects exactly one argument at {:?} What it means
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.
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
Example fix
// before arr.push(a, b) // after arr.push(a); arr.push(b);
Defensive patterns
Strategy: validation
Validate before calling
if (args.length !== 1) { throw new Error('push() expects exactly one argument'); } Try / catch
try { arr.push(...items); } catch (e) { if (String(e).includes('push() expects exactly one argument')) { items.forEach(i => arr.push(i)); } else { throw e; } } Prevention
- Call push with exactly one argument
- Loop to append multiple items
- Never rely on varargs semantics
When it happens
Trigger: `arr.push()` with no arguments, or `arr.push(a, b)` with multiple arguments.
Common situations: Porting from languages whose push accepts varargs (e.g. Ruby or JS spread of multiple items); forgetting the argument when pushing a computed value.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- push() can only be called on a variable at
- push() can only be called on arrays at
- arity mismatch: expected
- division by zero at
- division by zero in /= operator
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/245ff060aeaa3a55.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:2274
arg_vals.push(expect_value(
evaluate_expr(
arg,
scopes,
thir,
run_llm_function,
watch_handler,
function_name,
)
.await?,
)?);
}
// Mutate the array
let mut receiver_val = receiver_cell.lock().unwrap();
match &mut *receiver_val {
BamlValueWithMeta::List(items, _) => {
if arg_vals.len() != 1 {
bail!("push() expects exactly one argument at {:?}", meta.0);
}
items.push(arg_vals[0].clone());
// Return void/unit
EvalValue::Value(BamlValueWithMeta::Null(meta.clone()))
}
_ => bail!("push() can only be called on arrays at {:?}", meta.0),
}
} else {
// Non-mutating methods
let receiver_val = expect_value(
evaluate_expr(
receiver,
scopes,
thir,
run_llm_function,
watch_handler,
function_name,
)View on GitHub (pinned to bd85ce9dee)