(hyprland) fix crash when failed to parse IPC message

IPC messages are parsed in a dedicated thread, and the thread terminates when
an exception is not caught, which causes the waybar process to crash with
SIGABORT.

While this issue might be related to Hyprland, it is really annoying to see
waybar crash. It would be better to catch those exceptions and report errors
instead of crashing.
master
yangyingchao 2024-05-22 12:18:23 +08:00
parent 8ad7c75d79
commit b8e68b0e63
1 changed files with 8 additions and 1 deletions

View File

@ -86,7 +86,14 @@ void IPC::startIPC() {
std::string messageReceived(buffer.data()); std::string messageReceived(buffer.data());
messageReceived = messageReceived.substr(0, messageReceived.find_first_of('\n')); messageReceived = messageReceived.substr(0, messageReceived.find_first_of('\n'));
spdlog::debug("hyprland IPC received {}", messageReceived); spdlog::debug("hyprland IPC received {}", messageReceived);
try {
parseIPC(messageReceived); parseIPC(messageReceived);
} catch (std::exception& e) {
spdlog::warn("Failed to parse IPC message: {}, reason: {}", messageReceived, e.what());
} catch (...) {
throw;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }