fix(cava): throw instead of exit() on a bad config

loadConfig() called exit(EXIT_FAILURE) when the cava config failed to load or
no input source was available, killing the whole bar. Throw std::runtime_error
instead: the factory/bar catch it at construction and disable only the cava
module. The read_thread_ also calls loadConfig() at runtime, so contain the
throw there too, logging instead of terminating.

Fixes #4456
This commit is contained in:
Alex
2026-07-05 23:06:37 +02:00
parent 699589b66a
commit 6d5d5f0768
+13 -5
View File
@@ -2,6 +2,8 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <stdexcept>
std::shared_ptr<waybar::modules::cava::CavaBackend> waybar::modules::cava::CavaBackend::inst( std::shared_ptr<waybar::modules::cava::CavaBackend> waybar::modules::cava::CavaBackend::inst(
const Json::Value& config) { const Json::Value& config) {
static auto* backend = new CavaBackend(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()); spdlog::warn("Cava backend. Read source error: {0}", e.what());
} }
read_thread_.sleep_for(fetch_input_delay_); 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 // Write outcoming data. Emit signals
out_thread_ = [this] { out_thread_ = [this] {
@@ -175,8 +183,9 @@ void waybar::modules::cava::CavaBackend::loadConfig() {
error_.length = 0; error_.length = 0;
if (!load_config(cfgPath, &prm_, &error_)) { if (!load_config(cfgPath, &prm_, &error_)) {
spdlog::error("cava backend. Error loading config. {0}", error_.message); // Throw, don't exit(): a bad config must disable only the cava module, not
exit(EXIT_FAILURE); // 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 // Override cava parameters by the user config
@@ -252,8 +261,7 @@ void waybar::modules::cava::CavaBackend::loadConfig() {
input_source_ = get_input(&audio_data_, &prm_); input_source_ = get_input(&audio_data_, &prm_);
if (!input_source_) { if (!input_source_) {
spdlog::error("cava backend API didn't provide input audio source method"); throw std::runtime_error("cava backend: API didn't provide an input audio source");
exit(EXIT_FAILURE);
} }
prm_.output = ::cava::output_method::OUTPUT_RAW; prm_.output = ::cava::output_method::OUTPUT_RAW;