]> granicus.if.org Git - icinga2/commitdiff
Bugfix: Exception for invalid messages wasn't properly dealt with.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 30 Apr 2012 06:22:30 +0000 (08:22 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 30 Apr 2012 06:22:30 +0000 (08:22 +0200)
base/configobject.cpp
base/dictionary.cpp
icinga/endpointmanager.cpp
jsonrpc/jsonrpcclient.cpp

index 2189348fe3ed728aeabd00a830e980334af12008..c0dfbe96e0e126eaaae6847739d555980339fa5b 100644 (file)
@@ -27,7 +27,7 @@ ConfigObject::ConfigObject(const string& type, const string& name)
 void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
 {
        if (m_Hive.lock())
-               throw InvalidArgumentException();
+               throw InvalidArgumentException("Config object already has a parent hive.");
 
        m_Hive = hive;
        OnPropertyChanged += bind_weak(&ConfigObject::PropertyChangedHandler, shared_from_this());
index 6db6d6a5989fe726ebbbe6d46b27ad18b6a17b12..4e8a25b70b7ff7e2cbee03c99258c600e44d6f44 100644 (file)
@@ -76,7 +76,7 @@ bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
        dictionary = dynamic_pointer_cast<Dictionary>(data.GetObject());
 
        if (dictionary == NULL)
-               throw InvalidArgumentException();
+               throw InvalidArgumentException("Property is not a dictionary.");
 
        *value = dictionary;
 
index dd05c96e7f4b95ecac2d18b499441e5df6d60262..e1ebfac96bbc2a73a104855062f702b66370d398 100644 (file)
@@ -128,7 +128,7 @@ void EndpointManager::SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRe
 
        string method;
        if (!request.GetMethod(&method))
-               throw InvalidArgumentException();
+               throw InvalidArgumentException("Message is missing the 'method' property.");
 
        for (list<Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
        {
index 8db0a1cb8f464c6c5c003180b174e811a8b2f570..e7f0f4c00b8424e7ac93cb7f27d4b9143a67e900 100644 (file)
@@ -19,26 +19,22 @@ void JsonRpcClient::SendMessage(const Message& message)
 
 int JsonRpcClient::DataAvailableHandler(const EventArgs& ea)
 {
-       Message message;
-       bool message_read;
-
        while (true) {
                try {
-                       message_read = Netstring::ReadMessageFromFIFO(GetRecvQueue(), &message);
+                       Message message;
+
+                       if (Netstring::ReadMessageFromFIFO(GetRecvQueue(), &message)) {
+                               NewMessageEventArgs nea;
+                               nea.Source = shared_from_this();
+                               nea.Message = message;
+                               OnNewMessage(nea);
+                       }
                } catch (const Exception& ex) {
-                       cerr << "Exception while reading from JSON-RPC client: " << ex.GetMessage() << endl;
+                       Application::Log("Exception while processing message from JSON-RPC client: " + ex.GetMessage());
                        Close();
 
                        return 1;
                }
-       
-               if (!message_read)
-                       break;
-
-               NewMessageEventArgs nea;
-               nea.Source = shared_from_this();
-               nea.Message = message;
-               OnNewMessage(nea);
        }
 
        return 0;