{"record":{"id":"f681a0f4409a7449","repo":"BoundaryML/baml","slug":"startswith-method-takes-exactly-1-argument-at","errorCode":null,"errorMessage":"startsWith() method takes exactly 1 argument at {:?}","messagePattern":"startsWith\\(\\) method takes exactly 1 argument at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2897,"sourceCode":"                bail!(\"includes() method takes exactly 1 argument at {:?}\", meta.0);\n            }\n            let BamlValueWithMeta::String(search, _) = &args[0] else {\n                bail!(\"includes() argument must be a string at {:?}\", meta.0);\n            };\n            Ok(BamlValueWithMeta::Bool(\n                s.contains(search.as_str()),\n                meta.clone(),\n            ))\n        }\n        \"startsWith\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\n                    \"startsWith() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if args.len() != 1 {\n                bail!(\n                    \"startsWith() method takes exactly 1 argument at {:?}\",\n                    meta.0\n                );\n            }\n            let BamlValueWithMeta::String(prefix, _) = &args[0] else {\n                bail!(\"startsWith() argument must be a string at {:?}\", meta.0);\n            };\n            Ok(BamlValueWithMeta::Bool(\n                s.starts_with(prefix.as_str()),\n                meta.clone(),\n            ))\n        }\n        \"endsWith\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\n                    \"endsWith() method only available on strings at {:?}\",\n                    meta.0\n                );","sourceCodeStart":2879,"sourceCodeEnd":2915,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2879-L2915","documentation":"THIR interpreter runtime error: `startsWith()` was invoked with an argument count other than exactly one. The method takes a single string prefix argument; zero or multiple arguments fail the arity check at evaluation time.","triggerScenarios":"Calling `s.startsWith()` with no argument, or with multiple arguments — BAML's startsWith has no position/offset parameter unlike JavaScript's String.prototype.startsWith.","commonSituations":"Porting JavaScript code using `s.startsWith(prefix, position)` and keeping the second argument; omitting the argument when translating from a different prefix-check API.","solutions":["Pass exactly one string argument: `s.startsWith(prefix)`.","If a positional check is needed, slice the string first (e.g. via substring-style operations) or move the logic to the host language.","Verify the intended method and its arity against BAML's string method set."],"exampleFix":"// before\nlet ok = path.startsWith(\"/api\", 4);\n// after\nlet ok = path.startsWith(\"/api\");","handlingStrategy":"validation","validationCode":"const call = src.match(/\\.startsWith\\s*\\(([^)]*)\\)/);\nif (call && call[1].split(',').filter(a => a.trim()).length !== 1) {\n  throw new Error('startsWith() takes exactly 1 argument: ' + call[0]);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await b.Function(args);\n} catch (e) {\n  if (String(e.message).includes('startsWith() method takes exactly 1 argument')) {\n    // fix the arity at the reported span and re-run\n  }\n  throw e;\n}","preventionTips":["Drop JS-style position arguments — BAML's startsWith() takes one argument only.","For offset prefix checks, slice the string first.","Lint BAML sources for startsWith() calls with zero or multiple arguments."],"tags":["baml","interpreter","string-methods","wrong-arity"],"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"}