Skip to content

Commit 62f3cc1

Browse files
committed
fix(commands): improve error handling in GetKeysFromCommand for missing key arguments
1 parent cca5fa8 commit 62f3cc1

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/commands/commander.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ StatusOr<std::vector<int>> CommandTable::GetKeysFromCommand(const CommandAttribu
190190
return {Status::NotOK, "Invalid syntax found in this command arguments: " + s.Msg()};
191191
}
192192

193-
bool has_key_args = true;
193+
Status status;
194194
std::vector<int> key_indexes;
195195

196196
attributes->ForEachKeyRange(
197-
[&key_indexes, &cmd_tokens](const std::vector<std::string> &, CommandKeyRange key_range) {
198-
key_range.ForEachKeyIndex([&key_indexes](int i) { key_indexes.push_back(i); }, cmd_tokens.size());
197+
[&](const std::vector<std::string> &, CommandKeyRange key_range) {
198+
key_range.ForEachKeyIndex([&](int i) { key_indexes.push_back(i); }, cmd_tokens.size());
199199
},
200-
cmd_tokens, [&has_key_args](const auto &) { has_key_args = false; });
200+
cmd_tokens, [&](const auto &) { status = {Status::NotOK, "The command has no key arguments"}; });
201201

202-
if (!has_key_args) {
203-
return {Status::NotOK, "The command has no key arguments"};
202+
if (!status) {
203+
return status;
204204
}
205205

206206
return key_indexes;

0 commit comments

Comments
 (0)