Add send_command variant that exposes error details

This commit is contained in:
2025-01-03 22:29:07 +01:00
parent a7ae06060a
commit 06abdd693e
2 changed files with 16 additions and 2 deletions

View File

@@ -287,6 +287,8 @@ public:
*/
bool send_command(const std::string& command) const;
bool send_command(const std::string& command, std::optional<std::string>& error_info) const;
/**
* Request a list of workspaces
* @return List of workspaces

View File

@@ -632,7 +632,7 @@ std::shared_ptr<bar_config_t> connection::get_bar_config(const std::string& na
}
bool connection::send_command(const std::string& command) const {
bool connection::send_command(const std::string& command, std::optional<std::string>& error_info) const {
#define i3IPC_TYPE_STR "COMMAND"
auto buf = i3_msg(m_main_socket, ClientMessageType::COMMAND, command);
Json::Value root;
@@ -646,13 +646,25 @@ bool connection::send_command(const std::string& command) const {
} else {
Json::Value error = payload["error"];
if (!error.isNull()) {
I3IPC_ERR("Failed to execute command: " << error.asString())
error_info = error.asString();
} else {
error_info.reset();
}
return false;
}
#undef i3IPC_TYPE_STR
}
bool connection::send_command(const std::string& command) const {
std::optional<std::string> error_info{};
bool result = send_command(command, error_info);
if (!error_info.has_value()) {
I3IPC_ERR("Failed to execute command: " << error_info.value());
}
return result;
}
int32_t connection::get_main_socket_fd() { return m_main_socket; }
int32_t connection::get_event_socket_fd() { return m_event_socket; }