From 3fd25e9e497d3c6e7403642b4ae6a5eb91737017 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Mon, 9 Dec 2024 01:54:14 -0800 Subject: [PATCH] Don't fall back to `help` command when command is empty This masked issues in Bazel wrappers in a very confusing way. Fixes #24577 Closes #24579. PiperOrigin-RevId: 704193424 Change-Id: Iaf486b9eb5764073439be9968f449eaf172667ca --- src/main/cpp/option_processor.cc | 8 ++++++++ src/test/shell/integration/client_test.sh | 5 +++++ 2 files changed, 13 insertions(+) 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"