{"record":{"id":"5beac34a67f67723","repo":"bazelbuild/bazel","slug":"usage-s-command-arg1-args","errorCode":null,"errorMessage":"\nUsage: %s -- command arg1 @args\n","messagePattern":"\nUsage: (.+?) -- command arg1 @args\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/tools/linux-sandbox-options.cc","lineNumber":49,"sourceCode":"\n#include \"src/main/tools/logging.h\"\n#include \"src/main/tools/process-tools.h\"\n\nusing std::ifstream;\nusing std::unique_ptr;\nusing std::vector;\n\nstruct Options opt;\n\n// Print out a usage error. argc and argv are the argument counter and vector,\n// fmt is a format, string for the error message to print.\nstatic void Usage(char *program_name, const char *fmt, ...) {\n  va_list ap;\n  va_start(ap, fmt);\n  vfprintf(stderr, fmt, ap);\n  va_end(ap);\n\n  fprintf(stderr, \"\\nUsage: %s -- command arg1 @args\\n\", program_name);\n  fprintf(stderr,\n          \"\\nPossible arguments:\\n\"\n          \"  -W <working-dir>  working directory (uses current directory if \"\n          \"not specified)\\n\"\n          \"  -T <timeout>  timeout after which the child process will be \"\n          \"terminated with SIGTERM\\n\"\n          \"  -t <timeout>  in case timeout occurs, how long to wait before \"\n          \"killing the child with SIGKILL\\n\"\n          \"  -i  on receipt of a SIGINT, forward it to the child process as a \"\n          \"SIGTERM first and then as a SIGKILL after the -T timeout\\n\"\n          \"  -l <file>  redirect stdout to a file\\n\"\n          \"  -L <file>  redirect stderr to a file\\n\"\n          \"  -w <file>  make a file or directory writable for the sandboxed \"\n          \"process\\n\"\n          \"  -e <dir>  mount an empty tmpfs on a directory\\n\"\n          \"  -M/-m <source/target>  directory to mount inside the sandbox\\n\"\n          \"    Multiple directories can be specified and each of them will be \"\n          \"mounted readonly.\\n\"","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/tools/linux-sandbox-options.cc#L31-L67","documentation":"Usage() is linux-sandbox's argument parser error path: after printing the specific parse error via vfprintf, it prints this usage line (followed by the option list for -W/-T/-t/-i/-l/-L etc.) and exits nonzero. Bazel invokes linux-sandbox internally for sandboxed spawn actions, so an end user seeing it means the tool was called with malformed flags or a direct manual invocation got the syntax wrong.","triggerScenarios":"Calling linux-sandbox directly without '--' or with unknown short options; a Bazel version mismatch where the client generates spawn args the deployed linux-sandbox binary does not understand; hand-testing the tool and forgetting the required '-- command' separator.","commonSituations":"Mixing binaries from different Bazel versions in the output base; debugging sandbox behavior by running the tool copied from --subcommands output and mangling flags.","solutions":["If reproducing manually, follow the printed grammar: linux-sandbox <flags> -- <command> <args...> with flags exactly as they appeared in --subcommands.","Run the real build with --sandbox_debug --subcommands to capture the pristine invocation instead of retyping it.","If seen during normal builds, clean version skew: bazel clean --expunge or reinstall one consistent Bazel version so client and tools match.","Check that no wrapper script is inserting extra arguments before '--'."],"exampleFix":"# before: linux-sandbox /bin/true  (missing --)\n# after:\nlinux-sandbox -W /tmp/w -- /bin/true","handlingStrategy":"validation","validationCode":"// if wrapping the tool, validate argv shape before exec\nbool LooksValid(const std::vector<std::string> &argv) {\n  for (size_t i = 1; i < argv.size(); ++i)\n    if (argv[i] == \"--\") return i + 1 < argv.size();\n  return false; // missing '--' or no command after it\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always end flags with '--' and then the command; never reorder.","Copy argv verbatim from --subcommands output when reproducing.","Keep one Bazel version installed to avoid client/tool flag drift.","Use --sandbox_debug to inspect failures without the sandbox being torn down."],"tags":["c","sandbox","usage","cli","argument-parsing","linux"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}