diff --git a/src/riemannpp/attribute.cpp b/src/riemannpp/attribute.cpp index a948462..031e3d7 100644 --- a/src/riemannpp/attribute.cpp +++ b/src/riemannpp/attribute.cpp @@ -60,7 +60,7 @@ attribute::set(const std::string& key, const std::string& value) { int result = riemann_attribute_set(d_attribute.get(), key.c_str(), value.c_str()); if (-1 == result) { - throw internal_exception(); + throw internal_exception(errno, "failed to set attribute for key: " + key + ", with value: " + value); } } @@ -68,7 +68,7 @@ void attribute::set_key(const std::string& key) { int result = riemann_attribute_set_key(d_attribute.get(), key.c_str()); if (-1 == result) { - throw internal_exception(); + throw internal_exception(errno, "failed to set attribute key " + key); } } @@ -76,7 +76,7 @@ void attribute::set_value(const std::string& value) { int result = riemann_attribute_set_value(d_attribute.get(), value.c_str()); if (-1 == result) { - throw internal_exception(); + throw internal_exception(errno, "failed to set attribute value " + value); } } diff --git a/src/riemannpp/client.cpp b/src/riemannpp/client.cpp index 6ace0e8..f4705a5 100644 --- a/src/riemannpp/client.cpp +++ b/src/riemannpp/client.cpp @@ -41,7 +41,7 @@ client::client(client_type type, const std::string& host, int port) { d_client = riemann_client_create(riemann_client_type_t(type), host.c_str(), port); if (!d_client) { - throw internal_exception(); + throw internal_exception(errno, "failed to create riemann client"); } } @@ -64,7 +64,12 @@ client::connect(client_type type, const std::string& host, int port) { int result = riemann_client_connect(d_client, riemann_client_type_t(type), host.c_str(), port); if (0 != result) { - throw internal_exception(); + std::string message; + message += "failed to connect client to "; + message += host; + message += ":"; + message += std::to_string(port); + throw internal_exception(errno, message); } } @@ -72,7 +77,7 @@ void client::disconnect() { int result = riemann_client_disconnect(d_client); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to disconnect client"); } } @@ -80,7 +85,7 @@ void client::send(message&& m) { int result = riemann_client_send_message(d_client, m.release()); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to send message"); } } @@ -99,7 +104,7 @@ void client::send_oneshot(message&& m) { int result = riemann_client_send_message_oneshot(d_client, m.release()); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to send oneshot message"); } } diff --git a/src/riemannpp/event.cpp b/src/riemannpp/event.cpp index ffc6c92..207d20f 100644 --- a/src/riemannpp/event.cpp +++ b/src/riemannpp/event.cpp @@ -61,7 +61,7 @@ void event::tag_add(const std::string& tag) { int result = riemann_event_tag_add(d_event.get(), tag.c_str()); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to add event tag: " + tag); } } @@ -75,7 +75,7 @@ void event::attribute_add(attribute&& a) { int result = riemann_event_attribute_add(d_event.get(), a.release()); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to add event attribute"); } } diff --git a/src/riemannpp/event.hpp b/src/riemannpp/event.hpp index 196c2ed..986f948 100644 --- a/src/riemannpp/event.hpp +++ b/src/riemannpp/event.hpp @@ -170,7 +170,7 @@ namespace riemannpp { void event::set(const event_field field, const T& value) { int result = riemann_event_set(d_event.get(), field, value, RIEMANN_EVENT_FIELD_NONE); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to set event field"); } } diff --git a/src/riemannpp/exception.hpp b/src/riemannpp/exception.hpp index baa2852..8340353 100644 --- a/src/riemannpp/exception.hpp +++ b/src/riemannpp/exception.hpp @@ -49,19 +49,14 @@ namespace riemannpp { int d_error; std::string d_reason; public: - // Default constructor. Will construct the base exception class with - // the string error deduced by strerror, and store errno. - internal_exception() - : exception(strerror(errno)) - , d_error(errno) - , d_reason(strerror(errno)) {} - // Construct an internal exception with the given reason. Behaves the // same as the default constructor, with the exception being that the // reason string is overridden by the given parameter. - internal_exception(const std::string& reason) - : exception(strerror(errno)) - , d_error(errno) + internal_exception(int error, std::string const & reason) + : exception( + reason + ", error: " + strerror(error) + ) + , d_error(error) , d_reason(reason) {} // Destructor. diff --git a/src/riemannpp/message.cpp b/src/riemannpp/message.cpp index 421a5a9..b568063 100644 --- a/src/riemannpp/message.cpp +++ b/src/riemannpp/message.cpp @@ -63,7 +63,7 @@ void message::set_event(event& e) { int result = riemann_message_set_events(d_message.get(), e.release(), nullptr); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to set event"); } } @@ -76,7 +76,7 @@ void message::set_query(query& q) { int result = riemann_message_set_query(d_message.get(), q.release()); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to set query"); } } diff --git a/src/riemannpp/query.cpp b/src/riemannpp/query.cpp index dbca351..5632dd8 100644 --- a/src/riemannpp/query.cpp +++ b/src/riemannpp/query.cpp @@ -59,7 +59,7 @@ void query::set_string(const std::string& query) { int result = riemann_query_set_string(d_query.get(), query.c_str()); if (0 != result) { - throw internal_exception(); + throw internal_exception(errno, "failed to set query string: " + query); } }