Commit 36c080d7 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

[trac742] Log error events

parent 6154d0aa
......@@ -13,3 +13,23 @@
# PERFORMANCE OF THIS SOFTWARE.
$NAMESPACE isc::cc
% CC_CONN_ERROR error connecting to message queue (%1)
% CC_NO_MSGQ unable to connect to message queue (%1)
% CC_WRITE_ERROR error writing data to command channel (%1)
% CC_LENGTH_NOT_READY length not ready
% CC_READ_EXCEPTION error reading data from command channel (%1)
% CC_TIMEOUT timeout reading data from command channel
% CC_READ_ERROR error reading data from command channel (%1)
% CC_ZERO_LENGTH invalid message length (0)
% CC_ASYNC_READ_FAILED asynchronous read failed
% CC_INVALID_LENGTHS invalid length parameters (%1, %2)
......@@ -14,6 +14,7 @@
#include <config.h>
#include <cc/session_config.h>
#include <cc/logger.h>
#include <stdint.h>
......@@ -121,9 +122,11 @@ SessionImpl::establish(const char& socket_file) {
socket_.connect(asio::local::stream_protocol::endpoint(&socket_file),
error_);
} catch(const asio::system_error& se) {
LOG_FATAL(logger, CC_CONN_ERROR).arg(se.what());
isc_throw(SessionError, se.what());
}
if (error_) {
LOG_FATAL(logger, CC_NO_MSGQ).arg(error_.message());
isc_throw(SessionError, "Unable to connect to message queue: " <<
error_.message());
}
......@@ -140,6 +143,7 @@ SessionImpl::writeData(const void* data, size_t datalen) {
try {
asio::write(socket_, asio::buffer(data, datalen));
} catch (const asio::system_error& asio_ex) {
LOG_FATAL(logger, CC_WRITE_ERROR).arg(asio_ex.what());
isc_throw(SessionError, "ASIO write failed: " << asio_ex.what());
}
}
......@@ -151,6 +155,7 @@ SessionImpl::readDataLength() {
if (ret_len == 0) {
readData(&data_length_, sizeof(data_length_));
if (data_length_ == 0) {
LOG_ERROR(logger, CC_LENGTH_NOT_READY);
isc_throw(SessionError, "ASIO read: data length is not ready");
}
ret_len = ntohl(data_length_);
......@@ -199,9 +204,11 @@ SessionImpl::readData(void* data, size_t datalen) {
// asio::error_code evaluates to false if there was no error
if (*read_result) {
if (*read_result == asio::error::operation_aborted) {
LOG_ERROR(logger, CC_TIMEOUT);
isc_throw(SessionTimeout,
"Timeout while reading data from cc session");
} else {
LOG_ERROR(logger, CC_READ_ERROR).arg(read_result->message());
isc_throw(SessionError,
"Error while reading data from cc session: " <<
read_result->message());
......@@ -210,6 +217,7 @@ SessionImpl::readData(void* data, size_t datalen) {
} catch (const asio::system_error& asio_ex) {
// to hide ASIO specific exceptions, we catch them explicitly
// and convert it to SessionError.
LOG_FATAL(logger, CC_READ_EXCEPTION).arg(asio_ex.what());
isc_throw(SessionError, "ASIO read failed: " << asio_ex.what());
}
}
......@@ -233,10 +241,12 @@ SessionImpl::internalRead(const asio::error_code& error,
assert(bytes_transferred == sizeof(data_length_));
data_length_ = ntohl(data_length_);
if (data_length_ == 0) {
LOG_ERROR(logger, CC_ZERO_LENGTH);
isc_throw(SessionError, "Invalid message length (0)");
}
user_handler_();
} else {
LOG_ERROR(logger, CC_ASYNC_READ_FAILED);
isc_throw(SessionError, "asynchronous read failed");
}
}
......@@ -374,6 +384,7 @@ Session::recvmsg(ConstElementPtr& env, ConstElementPtr& msg,
unsigned short header_length = ntohs(header_length_net);
if (header_length > length || length < 2) {
LOG_ERROR(logger, CC_INVALID_LENGTHS).arg(length).arg(header_length);
isc_throw(SessionError, "Length parameters invalid: total=" << length
<< ", header=" << header_length);
}
......
......@@ -14,9 +14,13 @@
#include <gtest/gtest.h>
#include <util/unittests/run_all.h>
#include <log/logger_support.h>
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
isc::log::initLogger();
return (isc::util::unittests::run_all());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment