{"record":{"id":"632bfe0ad51d0213","repo":"bazelbuild/bazel","slug":"unknown-flag-s","errorCode":null,"errorMessage":"unknown flag: %s","messagePattern":"unknown flag: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/cmd/Main.java","lineNumber":197,"sourceCode":"      if (!args[i].startsWith(\"-\")) {\n        break;\n      }\n      if (args[i].equals(\"--\")) {\n        i++;\n        break;\n      }\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) {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/cmd/Main.java#L179-L215","documentation":"The Starlark interpreter CLI supports a fixed flag set: -c <cmd>, -cpuprofile <file>, and '--'. Any other token starting with '-' during the flag-parsing prefix is rejected with this IOException ('unknown flag: X') before the script runs.","triggerScenarios":"Passing unsupported flags like `starlark -v script.star`, `--verbose`, `-Dkey=val`, or a script path that begins with '-'; forgetting '--' before a filename that starts with '-'.","commonSituations":"Users assuming this CLI shares flags with the Bazel client or the go starlark binary; passing JVM system properties to the wrong side of '--'; renamed flags after switching interpreter distributions.","solutions":["Remove the unsupported flag; only -c, -cpuprofile and -- are accepted.","Use '--' to end flag parsing when a positional argument starts with '-': `starlark -- -weird.star`.","Pass JVM options to the java launcher (before the class/jar), not to this CLI."],"exampleFix":"# before\nstarlark -Dfoo=bar script.star\n\n# after\njava -Dfoo=bar -cp starlark.jar net.starlark.java.cmd.Main script.star","handlingStrategy":"validation","validationCode":"# Whitelist flags before forwarding\nfor a in \"$@\"; do\n  case \"$a\" in\n    -c|-cpuprofile|--|*.star) ;;\n    -*) echo \"unsupported flag: $a\" >&2; exit 2 ;;\n  esac\ndone\nexec starlark \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the CLI's own docs; it supports only -c, -cpuprofile and '--'.","Pass JVM options to java, not to the Starlark CLI.","Use '--' before arguments starting with '-'."],"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"}