Set error if error wasn't set by handler 90/87090/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 5 Sep 2016 10:06:03 +0000 (12:06 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 6 Sep 2016 14:15:23 +0000 (07:15 -0700)
Set to give clue to client code what happened wrong.

Change-Id: I5c8666c121231e2fbede2571d32eb94139df8df5

src/manifest_parser/manifest_parser_impl.cc

index 1542f323ea1e37972c123d0b77063929c6f6db16..da258f033a84d8b2c17f481db81da0ac578cd3e5 100644 (file)
@@ -21,8 +21,9 @@ void SetError(const std::string& message, std::string* error) {
   *error = message;
 }
 
-const char kErrMsgNoPath[] = "Path not specified.";
-const char kErrMsgInvalidPath[] = "Invalid path.";
+const char kErrMsgNoPath[] = "Path not specified";
+const char kErrMsgInvalidPath[] = "Invalid path";
+const char kErrMsgInvalidXml[] = "Invalid xml file";
 
 }  // namespace
 
@@ -55,8 +56,10 @@ bool ManifestParserImpl::ParseManifest(const bf::path& manifest_path,
 
   manifest_ =
       parser::LoadManifest(manifest_path.string(), &error_, constraints);
-  if (!manifest_.get())
+  if (!manifest_.get()) {
+    SetError(kErrMsgInvalidXml, &error_);
     return false;
+  }
   if (!ParseManifestData(&error_))
     return false;
   if (!ValidateAppManifest(&error_))
@@ -72,8 +75,13 @@ bool ManifestParserImpl::ValidateAppManifest(std::string* error) {
     auto handler = p.second;
     if (manifest_data_.find(p.first) != manifest_data_.end() &&
         !handler->Validate(*GetManifestData(handler->Key()).get(),
-            manifest_data_, error))
+            manifest_data_, error)) {
+      if (error->empty()) {
+        *error = std::string("'") + handler->Key() +
+            "'' handler failed to Validate() without setting error message";
+      }
       return false;
+    }
   }
   return true;
 }
@@ -96,6 +104,10 @@ bool ManifestParserImpl::ParseAppManifest(std::string* error) {
       if (output)
         manifest_data_[handler.second->Key()] = output;
     } else {
+      if (error->empty()) {
+        *error = std::string("'") + handler.second->Key() +
+            "'' handler failed to Parse() without setting error message";
+      }
       return false;
     }
   }