{"record":{"id":"811caf37ea75bb68","repo":"BoundaryML/baml","slug":"script-body-has-function-without-a-value","errorCode":null,"errorMessage":"script body has `--function` without a value","messagePattern":"script body has `--function` without a value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/run_command.rs","lineNumber":110,"sourceCode":"        }\n        if after_separator {\n            extra_args.push(token.to_string());\n            i += 1;\n            continue;\n        }\n\n        // Pre-separator: only `--function <value>` is recognized as a\n        // run-verb flag inside a script body in v1. Other run-verb flags\n        // (`--json-args`, `--include-generated`, etc.) are deliberately rejected\n        // here rather than silently dropped — the toml loader is the\n        // last chance to surface a typo before the script runs.\n        if token == \"--function\" {\n            i += 1;\n            if i < tokens.len() {\n                function = Some(tokens[i].clone());\n                i += 1;\n            } else {\n                anyhow::bail!(\"script body has `--function` without a value\");\n            }\n            continue;\n        }\n\n        if let Some(stripped) = token.strip_prefix(\"--\") {\n            anyhow::bail!(\n                \"unknown run-verb flag `--{stripped}` in script body. \\\n                 Only `--function <name>` is recognized before `--`; \\\n                 put target arguments after `--`.\"\n            );\n        }\n\n        anyhow::bail!(\n            \"unexpected token `{token}` in script body. \\\n             Script bodies have the shape `[--function <name>] [-- <target-args>...]`.\"\n        );\n    }\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/run_command.rs#L92-L128","documentation":"Parse guard for script bodies in baml.toml [scripts]: the token `--function` appeared as the last token of the body, so the expected function name after it is missing. V1 script bodies only accept the shape `[--function <name>] [-- <target-args>...]`; a dangling flag means the value was forgotten or misplaced.","triggerScenarios":"Calling `parse_script_body` with a token list where `--function` is the last token, e.g. a script body of `\"--function\"` with nothing after it.","commonSituations":"Hand-written script bodies missing the function name; shell scripts that dropped an argument; copy-paste truncation of a `baml run` invocation.","solutions":["Provide the function name after `--function`, e.g. `--function MyFunction`","If the function name contains `--`, keep it after the `--` separator for target args","Validate the script body before invoking"],"exampleFix":"// before\n[\"--function\"]\n// after\n[\"--function\", \"ExtractResume\"]","handlingStrategy":"validation","validationCode":"function validateScriptBody(tokens) {\n  const i = tokens.indexOf('--function');\n  if (i !== -1 && (i + 1 >= tokens.length || tokens[i + 1].startsWith('--') && tokens[i + 1] !== '--')) {\n    throw new Error('--function requires a name value');\n  }\n}","typeGuard":null,"tryCatchPattern":"try { await baml.run(scriptBody); } catch (e) { if (String(e).includes('`--function` without a value')) { console.error('Usage: [--function <name>] [-- <target-args>...]'); } else throw e; }","preventionTips":["Always pair `--function` with a name in script bodies","Build script bodies programmatically instead of string concatenation","Add a smoke test invoking the script body before shipping scripts"],"tags":["cli","argument-parsing","baml"],"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"}