From b636baf082d5e9354285d356ce0bdc5f95233af8 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 14 Jan 2019 21:22:00 +0100
Subject: [PATCH] signal_emitter: Don't swallow exceptions
If any signal receiver throws an exception for any reason after
receiving a signal, no one would find out about it because the signal
emitter just ignored exceptions
Also actually delivering the signal caused some exceptions because not
all signals have a receiver.
Resolves #1593
---
include/events/signal_emitter.hpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/include/events/signal_emitter.hpp b/include/events/signal_emitter.hpp
index dbe570be..ecae99a8 100644
--- a/include/events/signal_emitter.hpp
+++ b/include/events/signal_emitter.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "common.hpp"
+#include "components/logger.hpp"
#include "events/signal_receiver.hpp"
POLYBAR_NS
@@ -25,12 +26,15 @@ class signal_emitter {
template
bool emit(const Signal& sig) {
try {
- for (auto&& item : g_signal_receivers.at(id())) {
- if (item.second->on(sig)) {
- return true;
+ if (g_signal_receivers.find(id()) != g_signal_receivers.end()) {
+ for (auto&& item : g_signal_receivers.at(id())) {
+ if (item.second->on(sig)) {
+ return true;
+ }
}
}
- } catch (...) {
+ } catch (const std::exception& e) {
+ logger::make().err(e.what());
}
return false;