From d74a4fab7748033e3eeb45ddec6c341b0b502eb6 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Thu, 20 Apr 2023 13:51:51 +0200 Subject: [PATCH] i3: Better error reporting when connection fails Prints the output and exit code of 'i3 --get-socketpath' if it fails and prints the socket path if the connection fails. Ref polybar/i3ipcpp#13 Ref #2942 --- lib/i3ipcpp | 2 +- src/modules/i3.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/i3ipcpp b/lib/i3ipcpp index 85b444c0..b361f1e0 160000 --- a/lib/i3ipcpp +++ b/lib/i3ipcpp @@ -1 +1 @@ -Subproject commit 85b444c06267fbae8e9e06877cae6f03b42acbfb +Subproject commit b361f1e074e21f7b43e57f7545c3e2d1ca3e1658 diff --git a/src/modules/i3.cpp b/src/modules/i3.cpp index 15185477..f8b26f39 100644 --- a/src/modules/i3.cpp +++ b/src/modules/i3.cpp @@ -7,6 +7,8 @@ #include "modules/meta/base.inl" #include "utils/file.hpp" +#include + POLYBAR_NS namespace modules { @@ -18,10 +20,15 @@ namespace modules { m_router->register_action(EVENT_NEXT, [this]() { action_next(); }); m_router->register_action(EVENT_PREV, [this]() { action_prev(); }); - auto socket_path = i3ipc::get_socketpath(); - - if (!file_util::exists(socket_path)) { - throw module_error("Could not find socket: " + (socket_path.empty() ? "" : socket_path)); + try { + auto socket_path = i3ipc::get_socketpath(); + if (!file_util::exists(socket_path)) { + throw module_error("i3 socket does not exist: " + (socket_path.empty() ? "" : socket_path)); + } else { + m_log.info("%s: Found i3 socket at '%s'", name(), socket_path); + } + } catch (const i3ipc::ipc_error& e) { + throw module_error("Could not find i3 socket: " + string(e.what())); } m_ipc = std::make_unique();