AddTo will return AddToTypeProxy for convenience
Change-Id: If86496af0c68af31a3e0c618b0fae861975a4ebf
Reviewed-on: https://weave-review.googlesource.com/2321
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/commands/command_instance.cc b/src/commands/command_instance.cc
index dba14c4..fc9b0e7 100644
--- a/src/commands/command_instance.cc
+++ b/src/commands/command_instance.cc
@@ -37,10 +37,10 @@
bool ReportInvalidStateTransition(ErrorPtr* error,
Command::State from,
Command::State to) {
- Error::AddToPrintf(error, FROM_HERE, errors::commands::kInvalidState,
- "State switch impossible: '%s' -> '%s'",
- EnumToString(from).c_str(), EnumToString(to).c_str());
- return false;
+ return Error::AddToPrintf(error, FROM_HERE, errors::commands::kInvalidState,
+ "State switch impossible: '%s' -> '%s'",
+ EnumToString(from).c_str(),
+ EnumToString(to).c_str());
}
} // namespace
@@ -152,10 +152,9 @@
// Make sure the "parameters" property is actually an object.
const base::DictionaryValue* params_dict = nullptr;
if (!params_value->GetAsDictionary(¶ms_dict)) {
- Error::AddToPrintf(error, FROM_HERE, errors::json::kObjectExpected,
- "Property '%s' must be a JSON object",
- commands::attributes::kCommand_Parameters);
- return params;
+ return Error::AddToPrintf(error, FROM_HERE, errors::json::kObjectExpected,
+ "Property '%s' must be a JSON object",
+ commands::attributes::kCommand_Parameters);
}
params.reset(params_dict->DeepCopy());
} else {
@@ -180,10 +179,9 @@
// Get the command JSON object from the value.
const base::DictionaryValue* json = nullptr;
if (!value->GetAsDictionary(&json)) {
- Error::AddTo(error, FROM_HERE, errors::json::kObjectExpected,
- "Command instance is not a JSON object");
command_id->clear();
- return instance;
+ return Error::AddTo(error, FROM_HERE, errors::json::kObjectExpected,
+ "Command instance is not a JSON object");
}
// Get the command ID from 'id' property.
@@ -193,16 +191,15 @@
// Get the command name from 'name' property.
std::string command_name;
if (!json->GetString(commands::attributes::kCommand_Name, &command_name)) {
- Error::AddTo(error, FROM_HERE, errors::commands::kPropertyMissing,
- "Command name is missing");
- return instance;
+ return Error::AddTo(error, FROM_HERE, errors::commands::kPropertyMissing,
+ "Command name is missing");
}
auto parameters = GetCommandParameters(json, error);
if (!parameters) {
- Error::AddToPrintf(error, FROM_HERE, errors::commands::kCommandFailed,
- "Failed to validate command '%s'", command_name.c_str());
- return instance;
+ return Error::AddToPrintf(
+ error, FROM_HERE, errors::commands::kCommandFailed,
+ "Failed to validate command '%s'", command_name.c_str());
}
instance.reset(new CommandInstance{command_name, origin, *parameters});