Fix: cli: error handling 62/43962/2
authorMateusz Malicki <m.malicki2@samsung.com>
Wed, 15 Jul 2015 14:26:20 +0000 (16:26 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 15 Jul 2015 14:56:07 +0000 (07:56 -0700)
[Bug]           Not all errors are propagated up
[Cause]         Not all errors has non empty status message
[Solution]      Throw exception regardless of the status messages
[Verification]  Build, install, run vasum-cli

Change-Id: Idcbfdf519f1834b9046d3cdd59a7293cae629e3f

cli/command-line-interface.cpp

index 2b56594..3b100eb 100644 (file)
@@ -149,22 +149,16 @@ enum macvlan_mode macvlanFromString(const std::string& mode) {
 
 void CommandLineInterface::connect()
 {
-    string msg;
     VsmStatus status;
 
     CommandLineInterface::client = vsm_client_create();
     if (NULL == CommandLineInterface::client) {
-        msg = "Can't create client";
-        goto finish;
+        throw runtime_error("Can't create client");
     }
 
     status = vsm_connect(client);
     if (VSMCLIENT_SUCCESS != status) {
-        msg = vsm_get_status_message(CommandLineInterface::client);
-    }
-
-finish:
-    if (!msg.empty()) {
+        string msg = vsm_get_status_message(CommandLineInterface::client);
         vsm_client_free(CommandLineInterface::client);
         CommandLineInterface::client = NULL;
         throw runtime_error(msg);
@@ -184,25 +178,21 @@ void CommandLineInterface::disconnect()
     vsm_client_free(CommandLineInterface::client);
     CommandLineInterface::client = NULL;
 
-    if (!msg.empty()) {
+    if (VSMCLIENT_SUCCESS != status) {
         throw runtime_error(msg);
     }
 }
 
 void CommandLineInterface::executeCallback(const function<VsmStatus(VsmClient)>& fun)
 {
-    string msg;
     VsmStatus status;
 
     status = fun(CommandLineInterface::client);
     if (VSMCLIENT_SUCCESS != status) {
-        msg = vsm_get_status_message(CommandLineInterface::client);
-    }
-
-    if (!msg.empty()) {
-        throw runtime_error(msg);
+        throw runtime_error(vsm_get_status_message(CommandLineInterface::client));
     }
 }
+
 const std::string& CommandLineInterface::getName() const
 {
     return mName;