From 459cb212e5b6ca8da75436aa42ac6d1285529707 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 21 Mar 2014 13:42:37 +0000 Subject: [PATCH] Correctly handle failing to connect to the given session in client mode --- src/main.cc | 15 ++++++++++++++- src/remote.cc | 4 ++-- src/remote.hh | 7 +++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main.cc b/src/main.cc index c53477ba..9fed6433 100644 --- a/src/main.cc +++ b/src/main.cc @@ -228,6 +228,11 @@ int run_client(const String& session, const String& init_command) fputs("disconnected from server\n", stderr); return -1; } + catch (connection_failed& e) + { + fputs(e.what(), stderr); + return -1; + } return 0; } @@ -254,7 +259,15 @@ int kakoune(const ParametersParser& parser) } command += String{buf, buf + count}; } - send_command(parser.option_value("p"), command); + try + { + send_command(parser.option_value("p"), command); + } + catch (connection_failed& e) + { + fputs(e.what(), stderr); + return -1; + } return 0; } diff --git a/src/remote.cc b/src/remote.cc index cbad21f8..1140d6f7 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -448,7 +448,7 @@ std::unique_ptr connect_to(const String& session, std::unique_ptr< addr.sun_family = AF_UNIX; strncpy(addr.sun_path, filename.c_str(), sizeof(addr.sun_path) - 1); if (connect(sock, (sockaddr*)&addr, sizeof(addr.sun_path)) == -1) - throw runtime_error("connect to " + filename + " failed"); + throw connection_failed(filename); return std::unique_ptr{new RemoteClient{sock, std::move(ui), init_command}}; } @@ -463,7 +463,7 @@ void send_command(const String& session, const String& command) addr.sun_family = AF_UNIX; strncpy(addr.sun_path, filename.c_str(), sizeof(addr.sun_path) - 1); if (connect(sock, (sockaddr*)&addr, sizeof(addr.sun_path)) == -1) - throw runtime_error("connect to " + filename + " failed"); + throw connection_failed(filename); { Message msg(sock); diff --git a/src/remote.hh b/src/remote.hh index ac7a3cec..3881f349 100644 --- a/src/remote.hh +++ b/src/remote.hh @@ -10,6 +10,13 @@ namespace Kakoune struct peer_disconnected {}; +struct connection_failed : runtime_error +{ + connection_failed(const String& filename) + : runtime_error{"connect to " + filename + " failed"} + {} +}; + // A remote client handle communication between a client running on the server // and a user interface running on the local process. class RemoteClient