diff --git a/src/util/flag.cc b/src/util/flag.cc index 9a9a8b64..152ce58b 100644 --- a/src/util/flag.cc +++ b/src/util/flag.cc @@ -1,5 +1,6 @@ #include "flag.h" +#include #include #include "yaze_config.h" @@ -7,6 +8,15 @@ namespace yaze { namespace util { +namespace detail { + +[[noreturn]] void FlagParseFatal(const std::string& message) { + std::cerr << "[Flag Parser] " << message << std::endl; + std::exit(EXIT_FAILURE); +} + +} // namespace detail + void FlagParser::Parse(std::vector* tokens) { std::vector leftover; leftover.reserve(tokens->size()); @@ -38,7 +48,7 @@ void FlagParser::Parse(std::vector* tokens) { // Attempt to parse the flag (strip leading dashes in the registry). IFlag* flag_ptr = registry_->GetFlag(flag_name); if (!flag_ptr) { - throw std::runtime_error("Unrecognized flag: " + flag_name); + detail::FlagParseFatal("Unrecognized flag: " + flag_name); } // Set the parsed value on the matching flag. @@ -62,7 +72,7 @@ void FlagParser::Parse(std::vector* tokens) { std::string flag_name; if (!ExtractFlag(token, &flag_name)) { - throw std::runtime_error("Unrecognized flag: " + token); + detail::FlagParseFatal("Unrecognized flag: " + token); } } else { diff --git a/src/util/flag.h b/src/util/flag.h index 46bd89b0..1ada1aa0 100644 --- a/src/util/flag.h +++ b/src/util/flag.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -11,6 +10,10 @@ namespace yaze { namespace util { +namespace detail { +[[noreturn]] void FlagParseFatal(const std::string& message); +} + // Base interface for all flags. class IFlag { public: @@ -44,7 +47,7 @@ class Flag : public IFlag { std::stringstream ss(text); T parsed; if (!(ss >> parsed)) { - throw std::runtime_error("Failed to parse flag: " + name_); + detail::FlagParseFatal("Failed to parse flag: " + name_); } value_ = parsed; } @@ -70,8 +73,9 @@ inline void Flag::ParseValue(const std::string& text) { } else if (text == "false" || text == "0" || text == "no" || text == "off") { SetValue(false); } else { - throw std::runtime_error("Failed to parse boolean flag: " + name() + - " (expected true/false/1/0/yes/no/on/off, got: " + text + ")"); + detail::FlagParseFatal("Failed to parse boolean flag: " + name() + + " (expected true/false/1/0/yes/no/on/off, got: " + + text + ")"); } } diff --git a/src/util/util.cmake b/src/util/util.cmake index 60bb28c2..b40ab900 100644 --- a/src/util/util.cmake +++ b/src/util/util.cmake @@ -42,7 +42,13 @@ target_link_libraries(yaze_util PUBLIC # Add Abseil dependencies if gRPC is enabled # We link to grpc++ which transitively provides Abseil and ensures correct build order if(YAZE_ENABLE_GRPC) - target_link_libraries(yaze_util PUBLIC grpc++) + target_link_libraries(yaze_util PUBLIC + grpc++ + absl::status + absl::statusor + absl::strings + absl::str_format + ) endif() set_target_properties(yaze_util PROPERTIES