From b507a3f187f1bdf8c708db2698f3d0560c81e938 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Fri, 20 Sep 2019 14:40:35 +0300
Subject: [PATCH] Remove int exceptions

---
 components/net/cpp/include/ftl/net/peer.hpp     |  4 +++-
 components/net/cpp/include/ftl/net/universe.hpp |  2 +-
 components/net/cpp/src/dispatcher.cpp           | 12 +++---------
 3 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/components/net/cpp/include/ftl/net/peer.hpp b/components/net/cpp/include/ftl/net/peer.hpp
index 2c3e1fd63..976155ac9 100644
--- a/components/net/cpp/include/ftl/net/peer.hpp
+++ b/components/net/cpp/include/ftl/net/peer.hpp
@@ -6,6 +6,7 @@
 #endif
 
 #include <ftl/net/common.hpp>
+#include <ftl/exception.hpp>
 
 //#define GLOG_NO_ABBREVIATED_SEVERITIES
 #include <loguru.hpp>
@@ -343,7 +344,8 @@ R Peer::call(const std::string &name, ARGS... args) {
 	
 	if (!hasreturned) {
 		cancelCall(id);
-		throw 1;
+		LOG(ERROR) << "RPC Timeout: " << name;
+		throw ftl::exception("RPC failed with timeout");
 	}
 	
 	return result;
diff --git a/components/net/cpp/include/ftl/net/universe.hpp b/components/net/cpp/include/ftl/net/universe.hpp
index b4419b1f7..29680c601 100644
--- a/components/net/cpp/include/ftl/net/universe.hpp
+++ b/components/net/cpp/include/ftl/net/universe.hpp
@@ -378,7 +378,7 @@ R Universe::call(const ftl::UUID &pid, const std::string &name, ARGS... args) {
 	if (p == nullptr || !p->isConnected()) {
 		if (p == nullptr) DLOG(WARNING) << "Attempting to call an unknown peer : " << pid.to_string();
 		else DLOG(WARNING) << "Attempting to call an disconnected peer : " << pid.to_string();
-		throw -1;
+		throw ftl::exception("Calling disconnected peer");
 	}
 	return p->call<R>(name, args...);
 }
diff --git a/components/net/cpp/src/dispatcher.cpp b/components/net/cpp/src/dispatcher.cpp
index 3231b8ddc..7a5df5091 100644
--- a/components/net/cpp/src/dispatcher.cpp
+++ b/components/net/cpp/src/dispatcher.cpp
@@ -2,6 +2,7 @@
 #include <loguru.hpp>
 #include <ftl/net/dispatcher.hpp>
 #include <ftl/net/peer.hpp>
+#include <ftl/exception.hpp>
 #include <iostream>
 
 using ftl::net::Peer;
@@ -88,13 +89,6 @@ void ftl::net::Dispatcher::dispatch_call(Peer &s, const msgpack::object &msg) {
 				std::stringstream buf;
 				msgpack::pack(buf, res_obj);			
 				s.send("__return__", buf.str());*/
-			} catch (int e) {
-				//throw;
-				LOG(ERROR) << "Exception when attempting to call RPC (" << e << ")";
-		        /*response_t res_obj = std::make_tuple(1,id,msgpack::object(e),msgpack::object());
-				std::stringstream buf;
-				msgpack::pack(buf, res_obj);			
-				s.send("__return__", buf.str());*/
 			}
 		} else {
 			LOG(WARNING) << "No binding found for " << name;
@@ -150,7 +144,7 @@ void ftl::net::Dispatcher::enforce_arg_count(std::string const &func, std::size_
                                    std::size_t expected) {
     if (found != expected) {
     	LOG(FATAL) << "RPC argument missmatch for '" << func << "' - " << found << " != " << expected;
-        throw -1;
+        throw ftl::exception("RPC argument missmatch");
     }
 }
 
@@ -158,7 +152,7 @@ void ftl::net::Dispatcher::enforce_unique_name(std::string const &func) {
     auto pos = funcs_.find(func);
     if (pos != end(funcs_)) {
     	LOG(FATAL) << "RPC non unique binding for '" << func << "'";
-        throw -1;
+        throw ftl::exception("RPC binding not unique");
     }
 }
 
-- 
GitLab