{"record":{"id":"14ea05b798c9ef88","repo":"bazelbuild/bazel","slug":"too-many-positional-arguments","errorCode":null,"errorMessage":"too many positional arguments","messagePattern":"too many positional arguments","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/cmd/Main.java","lineNumber":203,"sourceCode":"      }\n      if (args[i].equals(\"-c\")) {\n        if (i + 1 == args.length) {\n          throw new IOException(\"-c <cmd> flag needs an argument\");\n        }\n        cmd = args[++i];\n      } else if (args[i].equals(\"-cpuprofile\")) {\n        if (i + 1 == args.length) {\n          throw new IOException(\"-cpuprofile <file> flag needs an argument\");\n        }\n        cpuprofile = args[++i];\n      } else {\n        throw new IOException(\"unknown flag: \" + args[i]);\n      }\n    }\n    // positional arguments\n    if (i < args.length) {\n      if (i + 1 < args.length) {\n        throw new IOException(\"too many positional arguments\");\n      }\n      file = args[i];\n    }\n\n    if (cpuprofile != null) {\n      FileOutputStream out = new FileOutputStream(cpuprofile);\n      Starlark.startCpuProfile(out, Duration.ofMillis(10));\n    }\n\n    int exit;\n    if (file == null) {\n      if (cmd != null) {\n        exit = execute(ParserInput.fromString(cmd, \"<command-line>\"));\n      } else {\n        readEvalPrintLoop();\n        exit = 0;\n      }\n    } else if (cmd == null) {","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/cmd/Main.java#L185-L221","documentation":"The Starlark interpreter CLI accepts at most one positional argument (the script file). After flag parsing, if more than one non-flag token remains, parsing aborts with this IOException. Note the script file's own arguments are not supported by this CLI — everything must reach the script through -c or the file itself.","triggerScenarios":"Running `starlark a.star b.star` or `starlark script.star --flag value`; script arguments passed after the filename.","commonSituations":"Treating this minimal CLI like a general-purpose interpreter that forwards argv to the script; batching multiple scripts in one invocation; leftover shell-glob expansions producing multiple files.","solutions":["Run one script per invocation: `starlark script.star`.","Pass data into the script via -c or embed it in the file instead of positional args.","Quote/limit shell globbing so exactly one file matches.","If argv forwarding is needed, use a wrapper that reads a single pre-processed script."],"exampleFix":"# before\nstarlark a.star b.star\n\n# after\nstarlark a.star && starlark b.star","handlingStrategy":"validation","validationCode":"# Count positional args before launch\nfiles=(); for a in \"$@\"; do [[ \"$a\" != -* ]] && files+=(\"$a\"); done\nif (( ${#files[@]} > 1 )); then echo \"only one script file allowed\" >&2; exit 2; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Invoke one script per process.","Pass script data via -c or generate a single combined file.","Quote globs in wrapper scripts."],"tags":["starlark","cli","argument-parsing"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}