diff --git a/src/modules/cava/cava_backend.cpp b/src/modules/cava/cava_backend.cpp index 6eb540c9..99f03e16 100644 --- a/src/modules/cava/cava_backend.cpp +++ b/src/modules/cava/cava_backend.cpp @@ -2,6 +2,8 @@ #include +#include + std::shared_ptr waybar::modules::cava::CavaBackend::inst( const Json::Value& config) { static auto* backend = new CavaBackend(config); @@ -20,7 +22,13 @@ waybar::modules::cava::CavaBackend::CavaBackend(const Json::Value& config) : con spdlog::warn("Cava backend. Read source error: {0}", e.what()); } read_thread_.sleep_for(fetch_input_delay_); - loadConfig(); + // loadConfig() now throws on failure; contain it so a runtime config error + // logs instead of terminating the process (#4456). + try { + loadConfig(); + } catch (const std::exception& e) { + spdlog::error("{}", e.what()); + } }; // Write outcoming data. Emit signals out_thread_ = [this] { @@ -175,8 +183,9 @@ void waybar::modules::cava::CavaBackend::loadConfig() { error_.length = 0; if (!load_config(cfgPath, &prm_, &error_)) { - spdlog::error("cava backend. Error loading config. {0}", error_.message); - exit(EXIT_FAILURE); + // Throw, don't exit(): a bad config must disable only the cava module, not + // kill the whole bar (#4456). Caught by the factory (ctor) / read_thread_. + throw std::runtime_error(std::string{"cava backend: error loading config: "} + error_.message); } // Override cava parameters by the user config @@ -252,8 +261,7 @@ void waybar::modules::cava::CavaBackend::loadConfig() { input_source_ = get_input(&audio_data_, &prm_); if (!input_source_) { - spdlog::error("cava backend API didn't provide input audio source method"); - exit(EXIT_FAILURE); + throw std::runtime_error("cava backend: API didn't provide an input audio source"); } prm_.output = ::cava::output_method::OUTPUT_RAW;