diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc index f68b135b535982..73821a6f7abd87 100644 --- a/src/main/cpp/option_processor.cc +++ b/src/main/cpp/option_processor.cc @@ -151,6 +151,14 @@ std::unique_ptr OptionProcessor::SplitCommandLine( std::move(path_to_binary), std::move(startup_args), "", {})); } string& command = args[i]; + // Distinguish an empty command from the case of no command above. + if (command.empty()) { + blaze_util::StringPrintf(error, + "Command cannot be the empty string.\n" + " For more info, run '%s help'.", + lowercase_product_name.c_str()); + return nullptr; + } // The rest are the command arguments. vector command_args(std::make_move_iterator(args.begin() + i + 1), diff --git a/src/test/shell/integration/client_test.sh b/src/test/shell/integration/client_test.sh index afe7812b866a8f..09865ad3739154 100755 --- a/src/test/shell/integration/client_test.sh +++ b/src/test/shell/integration/client_test.sh @@ -222,6 +222,11 @@ function test_no_arguments() { expect_log "Usage: b\\(laze\\|azel\\)" } +function test_empty_command() { + bazel '' >&$TEST_log && fail "Expected non-zero exit" + expect_log "Command cannot be the empty string." +} + function test_local_startup_timeout() { local output_base=$(bazel info output_base 2>"$TEST_log") || fail "bazel info failed"