buffet: Crash on detecting duplicate command definitions
BUG=chromium:448815
TEST=unittests, buffet_BasicDBusAPI still passes, indicating the daemon
starts up and runs correctly.
Change-Id: I5bee8f8538735b9294d239514d197ea46f17ff79
Reviewed-on: https://chromium-review.googlesource.com/240818
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Anton Muhin <antonm@chromium.org>
diff --git a/buffet/commands/command_dictionary.cc b/buffet/commands/command_dictionary.cc
index 58ab823..1dd0407 100644
--- a/buffet/commands/command_dictionary.cc
+++ b/buffet/commands/command_dictionary.cc
@@ -127,15 +127,10 @@
// daemon on the same device.
for (const auto& pair : new_defs) {
auto iter = definitions_.find(pair.first);
- if (iter != definitions_.end()) {
- chromeos::Error::AddToPrintf(
- error, FROM_HERE, errors::commands::kDomain,
- errors::commands::kDuplicateCommandDef,
- "Definition for command '%s' overrides an earlier "
- "definition in category '%s'",
- pair.first.c_str(), iter->second->GetCategory().c_str());
- return false;
- }
+ CHECK(iter == definitions_.end())
+ << "Definition for command '" << pair.first
+ << "' overrides an earlier definition in category '"
+ << iter->second->GetCategory().c_str() << "'";
}
// Now that we successfully loaded all the command definitions,
diff --git a/buffet/commands/command_dictionary_unittest.cc b/buffet/commands/command_dictionary_unittest.cc
index 10e7ec9..0519d88 100644
--- a/buffet/commands/command_dictionary_unittest.cc
+++ b/buffet/commands/command_dictionary_unittest.cc
@@ -107,18 +107,16 @@
error.reset();
}
-TEST(CommandDictionary, LoadCommands_RedefineInDifferentCategory) {
+TEST(CommandDictionaryDeathTest, LoadCommands_RedefineInDifferentCategory) {
// Redefine commands in different category.
buffet::CommandDictionary dict;
chromeos::ErrorPtr error;
auto json = CreateDictionaryValue(
"{'robot':{'jump':{'parameters':{},'results':{}}}}");
dict.LoadCommands(*json, "category1", nullptr, &error);
- EXPECT_FALSE(dict.LoadCommands(*json, "category2", nullptr, &error));
- EXPECT_EQ("duplicate_command_definition", error->GetCode());
- EXPECT_EQ("Definition for command 'robot.jump' overrides an earlier "
- "definition in category 'category1'", error->GetMessage());
- error.reset();
+ ASSERT_DEATH(dict.LoadCommands(*json, "category2", nullptr, &error),
+ ".*Definition for command 'robot.jump' overrides an "
+ "earlier definition in category 'category1'");
}
TEST(CommandDictionary, LoadCommands_CustomCommandNaming) {