aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/command_instance.cc31
1 files changed, 14 insertions, 17 deletions
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 @@ const EnumToStringMap<Command::Origin>::Map kMapOrigin[] = {
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 @@ std::unique_ptr<base::DictionaryValue> GetCommandParameters(
// Make sure the "parameters" property is actually an object.
const base::DictionaryValue* params_dict = nullptr;
if (!params_value->GetAsDictionary(&params_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 @@ std::unique_ptr<CommandInstance> CommandInstance::FromJson(
// 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 @@ std::unique_ptr<CommandInstance> CommandInstance::FromJson(
// 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});