From 2527515039f65eea4fa0c603743b4e21773f8f51 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Wed, 27 Feb 2019 15:22:09 +0200 Subject: [PATCH] Improve error reporting on invalid RPC arguments --- net/include/ftl/net/dispatcher.hpp | 2 +- net/include/ftl/net/socket.hpp | 1 + net/src/dispatcher.cpp | 16 ++++++++-------- net/src/protocol.cpp | 1 + net/src/socket.cpp | 1 - 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/net/include/ftl/net/dispatcher.hpp b/net/include/ftl/net/dispatcher.hpp index c358ad104..3d9465991 100644 --- a/net/include/ftl/net/dispatcher.hpp +++ b/net/include/ftl/net/dispatcher.hpp @@ -6,7 +6,7 @@ #include <memory> #include <tuple> #include <functional> -//#include <iostream> +#include <iostream> namespace ftl { diff --git a/net/include/ftl/net/socket.hpp b/net/include/ftl/net/socket.hpp index 6b0fc7a31..a3efdfc12 100644 --- a/net/include/ftl/net/socket.hpp +++ b/net/include/ftl/net/socket.hpp @@ -15,6 +15,7 @@ #include <winsock.h> #endif +#include <iostream> #include <sstream> #include <tuple> #include <vector> diff --git a/net/src/dispatcher.cpp b/net/src/dispatcher.cpp index bc7a842ac..8bbe3a1b4 100644 --- a/net/src/dispatcher.cpp +++ b/net/src/dispatcher.cpp @@ -60,8 +60,9 @@ void ftl::net::Dispatcher::dispatch_call(Socket &s, const msgpack::object &msg) //std::cout << " RESULT " << result.as<std::string>() << std::endl; s.send(FTL_PROTOCOL_RPCRETURN, buf.str()); - } catch (...) { - throw; + } catch (int e) { + //throw; + LOG(ERROR) << "Exception when attempting to call RPC (" << e << ")"; } } } @@ -76,16 +77,14 @@ void ftl::net::Dispatcher::dispatch_notification(Socket &s, msgpack::object cons auto &&name = std::get<1>(the_call); auto &&args = std::get<2>(the_call); - - std::cout << "RPC NOTIFY" << name << std::endl; auto it_func = funcs_.find(name); if (it_func != end(funcs_)) { try { auto result = (it_func->second)(args); - } catch (...) { - throw; + } catch (int e) { + throw e; } } } @@ -93,14 +92,15 @@ void ftl::net::Dispatcher::dispatch_notification(Socket &s, msgpack::object cons void ftl::net::Dispatcher::enforce_arg_count(std::string const &func, std::size_t found, std::size_t expected) { if (found != expected) { - throw; + LOG(FATAL) << "RPC argument missmatch - " << found << " != " << expected; + throw -1; } } void ftl::net::Dispatcher::enforce_unique_name(std::string const &func) { auto pos = funcs_.find(func); if (pos != end(funcs_)) { - throw; + throw -1; } } diff --git a/net/src/protocol.cpp b/net/src/protocol.cpp index 59444e69e..125477376 100644 --- a/net/src/protocol.cpp +++ b/net/src/protocol.cpp @@ -2,6 +2,7 @@ #include <ftl/net/socket.hpp> #include <ftl/net/protocol.hpp> #include <functional> +#include <iostream> using ftl::net::Socket; using ftl::net::Protocol; diff --git a/net/src/socket.cpp b/net/src/socket.cpp index 0eadd46ea..94a2909c7 100644 --- a/net/src/socket.cpp +++ b/net/src/socket.cpp @@ -396,7 +396,6 @@ int Socket::_send() { } Socket::~Socket() { - std::cerr << "DESTROYING SOCKET" << std::endl; close(); // Delete socket buffer -- GitLab