Add some error handlings 42/239542/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 27 Jul 2020 11:34:05 +0000 (20:34 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Thu, 30 Jul 2020 05:28:02 +0000 (05:28 +0000)
Change-Id: I498accc877b3fcf272fcb994b7b82b9dd3552cd0
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/api/theme_loader.cc
src/api/theme_loader.h
src/theme/dbus/request_broker.cc
src/theme/loader/theme_info_loader.cc

index 1fabfda..a5c73c6 100644 (file)
@@ -101,6 +101,10 @@ extern "C" EXPORT_API int theme_loader_load_current(theme_loader_h handle,
       static_cast<std::shared_ptr<ThemeInfoLoader>*>(handle);
 
   auto theme_info = (*p)->LoadCurrent();
+  if (!theme_info) {
+    LOG(ERROR) << "Failed to load current theme";
+    return THEME_MANAGER_ERROR_IO_ERROR;
+  }
   *cur_theme = static_cast<theme_h>(new std::shared_ptr<ThemeInfo>(theme_info));
   return THEME_MANAGER_ERROR_NONE;
 }
@@ -116,6 +120,10 @@ extern "C" EXPORT_API int theme_loader_load(theme_loader_h handle,
       = static_cast<std::shared_ptr<ThemeInfoLoader>*>(handle);
 
   auto theme_info = (*p)->Load(id);
+  if (!theme_info) {
+    LOG(ERROR) << "Failed to load theme " << id;
+    return THEME_MANAGER_ERROR_IO_ERROR;
+  }
   *theme = static_cast<theme_h>(new std::shared_ptr<ThemeInfo>(theme_info));
   return THEME_MANAGER_ERROR_NONE;
 }
@@ -174,6 +182,10 @@ extern "C" EXPORT_API int theme_loader_add_event(theme_loader_h handle,
   std::shared_ptr<ThemeInfoLoader>* p =
       static_cast<std::shared_ptr<ThemeInfoLoader>*>(handle);
   std::string result = (*p)->AddEvent(std::move(event_handler));
+  if (result.empty()) {
+    LOG(ERROR) << "Failed to add theme event";
+    return THEME_MANAGER_ERROR_IO_ERROR;
+  }
   *event_id = strdup(result.c_str());
   if (*event_id == nullptr) {
     LOG(ERROR) << "Out of memory";
index feed52b..02dfb2d 100644 (file)
@@ -92,6 +92,7 @@ int theme_loader_destroy(theme_loader_h handle);
  * @retval #THEME_MANAGER_ERROR_NONE              Successful
  * @retval #THEME_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #THEME_MANAGER_OUT_OF_MEMORY           Out of memory
+ * @retval #THEME_MANAGER_ERROR_IO_ERROR          I/O error
  * @see theme_loader_remove_event()
 */
 int theme_loader_add_event(theme_loader_h handle,
@@ -120,6 +121,7 @@ int theme_loader_remove_event(theme_loader_h handle, const char* event_id);
  *         otherwise a negative error value
  * @retval #THEME_MANAGER_ERROR_NONE              Successful
  * @retval #THEME_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #THEME_MANAGER_ERROR_IO_ERROR          I/O error
 */
 int theme_loader_load_current(theme_loader_h handle, theme_h *cur_theme);
 
@@ -134,6 +136,7 @@ int theme_loader_load_current(theme_loader_h handle, theme_h *cur_theme);
  *         otherwise a negative error value
  * @retval #THEME_MANAGER_ERROR_NONE              Successful
  * @retval #THEME_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #THEME_MANAGER_ERROR_IO_ERROR          I/O error
 */
 int theme_loader_load(theme_loader_h handle, const char *id, theme_h *theme);
 
index 5279dca..f8d2622 100644 (file)
@@ -236,6 +236,18 @@ tizen_base::Bundle RequestBroker::SendData(Command cmd,
     }
     return ErrorResultBundle();
   }
+
+  GDBusMessageType type = g_dbus_message_get_message_type(reply);
+  if (type != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) {
+    LOG(ERROR) << "Invalid reply message type: " << type;
+    if (type == G_DBUS_MESSAGE_TYPE_ERROR) {
+      if (g_dbus_message_to_gerror(reply, &err)) {
+        LOG(ERROR) << "error[" <<  err->message << "]";
+        g_error_free(err);
+      }
+    }
+    return ErrorResultBundle();
+  }
   GVariant* reply_body = g_dbus_message_get_body(reply);
   if (reply_body == nullptr) {
     LOG(ERROR) << "g_dbus_message_get_body() is failed";
@@ -244,6 +256,10 @@ tizen_base::Bundle RequestBroker::SendData(Command cmd,
 
   char* serialized = nullptr;
   g_variant_get(reply_body, "(&s)", &serialized);
+  if (!serialized) {
+    LOG(ERROR) << "Failed to get reply data";
+    return ErrorResultBundle();
+  }
   tizen_base::Bundle result(serialized);
   return result;
 }
index 4b83783..ebe6a13 100644 (file)
@@ -109,9 +109,14 @@ std::shared_ptr<ThemeInfo> ThemeInfoLoader::LoadCurrent() {
   tizen_base::Bundle reply =
     dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
   std::string str = reply.GetString(dbus::kCmdDataKey);
+  if (str.empty()) {
+    LOG(ERROR) << "Failed to load current theme info. Reply is empty";
+    return nullptr;
+  }
   tizen_base::Bundle serialized(str);
   if (serialized.IsEmpty()) {
-    LOG(ERROR) << "Failed to load current theme info";
+    LOG(ERROR) << "Failed to load current theme info. "
+               << "Invalid bundle from reply";
     return nullptr;
   }