Fix wrong exception handling 74/279574/4
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 12 Aug 2022 01:04:35 +0000 (10:04 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 12 Aug 2022 02:48:40 +0000 (11:48 +0900)
If the AppRequest() is not used to send the request, the result value
has to be converted using the aul_error_convert().
While creating the LocalizedInfo instance if the locale is empty, we
throw the exception. The previous implementation, AUL only checks whether
the locale is empty or not.

Change-Id: I6c25e1e9c415d6dc3e3be18862f34c88da2df980
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
aul/component/localized_info.cc
src/aul_comp_context.cc
src/aul_comp_info.cc

index 99ede26..0c0f488 100644 (file)
@@ -46,9 +46,7 @@ LocalizedInfo::Builder::operator LocalizedInfo*() {
 }
 
 void LocalizedInfo::Builder::Validate() {
-  if (locale_.empty() ||
-      icon_.empty() ||
-      label_.empty())
+  if (locale_.empty())
     THROW(AUL_R_ERROR);
 }
 
index ef2298f..b93e82c 100644 (file)
@@ -59,7 +59,7 @@ ComponentRunningContext* GetComponentRunningContext(
       .With(std::move(b))
       .SendSimply(AUL_SOCK_ASYNC);
   if (fd < 0)
-    THROW(aul_error_convert(fd));
+    THROW(fd);
 
   app_pkt_t* pkt;
   int ret = aul_sock_recv_reply_pkt(fd, &pkt);
@@ -92,7 +92,7 @@ GetComponentRunningContexts() {
   int fd = AppRequest(COMP_CONTEXT_FOREACH, getuid())
       .SendSimply(AUL_SOCK_ASYNC);
   if (fd < 0)
-    THROW(aul_error_convert(fd));
+    THROW(fd);
 
   std::vector<std::unique_ptr<ComponentRunningContext>> contexts;
   int ret = aul_sock_recv_pkt_with_cb(fd,
@@ -141,7 +141,7 @@ int SendRequest(ComponentRunningContext* context, int cmd) {
       .With(std::move(b))
       .SendSimply();
   if (ret < 0)
-    THROW(aul_error_convert(ret));
+    THROW(ret);
 
   return ret;
 }
index 36204ed..544579f 100644 (file)
@@ -64,7 +64,7 @@ std::string GetSystemLocale() {
 ComponentInfo* CreateComponentInfoFromAppPacket(
     app_pkt_t* pkt) {
   if (pkt->cmd != APP_GET_INFO_OK)
-    THROW(pkt->cmd);
+    THROW(aul_error_convert(pkt->cmd));
 
   bundle* kb = nullptr;
   if (pkt->opt & AUL_SOCK_BUNDLE) {
@@ -99,7 +99,7 @@ ComponentInfo* GetComponentInfo(const char* comp_id,
   app_pkt_t* pkt = nullptr;
   int ret = aul_sock_recv_reply_pkt(fd, &pkt);
   if (ret < 0)
-    THROW(ret);
+    THROW(aul_error_convert(ret));
 
   auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
       pkt, std::free);
@@ -128,7 +128,7 @@ std::vector<std::shared_ptr<ComponentInfo>> GetComponentInfos(uid_t uid) {
         }
       }, &component_infos);
   if (ret < 0)
-    THROW(ret);
+    THROW(aul_error_convert(ret));
 
   return component_infos;
 }
@@ -281,8 +281,11 @@ extern "C" API int aul_comp_info_get_icon(aul_comp_info_h handle,
   auto* info = static_cast<ComponentInfo*>(handle);
   try {
     auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
-    if (localized_info == nullptr)
-      return AUL_R_ENOENT;
+    if (localized_info == nullptr) {
+      localized_info = info->GetLocalizedInfo(kDefaultLocale);
+      if (localized_info == nullptr)
+        return AUL_R_ENOENT;
+    }
 
     *icon = localized_info->GetIcon().c_str();
   } catch (const Exception& e) {
@@ -303,8 +306,11 @@ extern "C" API int aul_comp_info_get_label(aul_comp_info_h handle,
   auto* info = static_cast<ComponentInfo*>(handle);
   try {
     auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
-    if (localized_info == nullptr)
-      return AUL_R_ENOENT;
+    if (localized_info == nullptr) {
+      localized_info = info->GetLocalizedInfo(kDefaultLocale);
+      if (localized_info == nullptr)
+        return AUL_R_ENOENT;
+    }
 
     *label = localized_info->GetLabel().c_str();
   } catch (const Exception& e) {
@@ -324,8 +330,11 @@ extern "C" API int aul_comp_info_get_localed_label(aul_comp_info_h handle,
 
   auto* info = static_cast<ComponentInfo*>(handle);
   auto* localized_info = info->GetLocalizedInfo(locale);
-  if (localized_info == nullptr)
-    return AUL_R_ENOENT;
+  if (localized_info == nullptr) {
+    localized_info = info->GetLocalizedInfo(kDefaultLocale);
+    if (localized_info == nullptr)
+      return AUL_R_ENOENT;
+  }
 
   *label = localized_info->GetLabel().c_str();
   return AUL_R_OK;