buffet: add object property parsing error informaion.
When parsing command definition/object schema and when there is
an error in object property definition, report the name of the
property in error. Add another error object to the error chain
with the property name being parsed.
BUG=None
TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2
Change-Id: I58e0008401395497a3515402c5464e820568617d
Reviewed-on: https://chromium-review.googlesource.com/209310
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/object_schema.cc b/buffet/commands/object_schema.cc
index a9cae20..82d1e6e 100644
--- a/buffet/commands/object_schema.cc
+++ b/buffet/commands/object_schema.cc
@@ -117,8 +117,13 @@
if (!prop)
return false;
base::DictionaryValue empty;
- if (!prop->FromJson(&empty, base_schema, error))
+ if (!prop->FromJson(&empty, base_schema, error)) {
+ Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropDef,
+ "Error in definition of property '%s'",
+ prop_name.c_str());
return false;
+ }
properties->insert(std::make_pair(prop_name, std::move(prop)));
return true;
}
@@ -172,8 +177,13 @@
base::DictionaryValue array_object;
array_object.SetWithoutPathExpansion(commands::attributes::kOneOf_Enum,
list->DeepCopy());
- if (!prop->FromJson(&array_object, base_schema, error))
+ if (!prop->FromJson(&array_object, base_schema, error)) {
+ Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropDef,
+ "Error in definition of property '%s'",
+ prop_name.c_str());
return false;
+ }
properties->insert(std::make_pair(prop_name, std::move(prop)));
return true;
}
@@ -248,8 +258,15 @@
type_name = base_schema->GetTypeAsString();
}
std::unique_ptr<PropType> prop = CreatePropType(type_name, prop_name, error);
- if (!prop || !prop->FromJson(dict, base_schema, error))
+ if (!prop)
return false;
+ if (!prop->FromJson(dict, base_schema, error)) {
+ Error::AddToPrintf(error, errors::commands::kDomain,
+ errors::commands::kInvalidPropDef,
+ "Error in definition of property '%s'",
+ prop_name.c_str());
+ return false;
+ }
properties->insert(std::make_pair(prop_name, std::move(prop)));
return true;
}
diff --git a/buffet/commands/prop_types.cc b/buffet/commands/prop_types.cc
index 71d1874..0df5bd1 100644
--- a/buffet/commands/prop_types.cc
+++ b/buffet/commands/prop_types.cc
@@ -86,7 +86,7 @@
if (base_schema && base_schema->GetType() != GetType()) {
Error::AddToPrintf(error, errors::commands::kDomain,
errors::commands::kPropTypeChanged,
- "Redefining a command of type %s as %s",
+ "Redefining a property of type %s as %s",
base_schema->GetTypeAsString().c_str(),
GetTypeAsString().c_str());
return false;