buffet: Better access to JSON properies.
We should be checking the return value of the getters to detect
failures instead of relying on the value of the out arguments.
BUG=None
TEST=cros_workon_make buffet --test&&manual
Change-Id: I93118ae659600af4017b4925dd0b8ec4bf14f4d8
Reviewed-on: https://chromium-review.googlesource.com/224930
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Anton Muhin <antonm@chromium.org>
Commit-Queue: Anton Muhin <antonm@chromium.org>
Tested-by: Anton Muhin <antonm@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 30cbb93..21638e8 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -629,19 +629,16 @@
auto abort_commands_cb = [] (const base::DictionaryValue& json) {
const base::ListValue* commands{nullptr};
- json.GetList("commands", &commands);
- if (commands) {
+ if (json.GetList("commands", &commands)) {
const size_t size{commands->GetSize()};
for (size_t i = 0; i < size; ++i) {
const base::DictionaryValue* command{nullptr};
- commands->GetDictionary(i, &command);
- if (!command) {
+ if (!commands->GetDictionary(i, &command)) {
LOG(WARNING) << "No command resource at " << i;
continue;
}
std::string command_state;
- command->GetString("state", &command_state);
- if (command_state.empty()) {
+ if (!command->GetString("state", &command_state)) {
LOG(WARNING) << "Command with no state at " << i;
continue;
}
@@ -652,8 +649,7 @@
continue;
}
std::string command_id;
- command->GetString("id", &command_id);
- if (command_id.empty()) {
+ if (!command->GetString("id", &command_id)) {
LOG(WARNING) << "Command with no ID at " << i;
continue;
}