Skip to content

Commit

Permalink
Campaignd: cleaned up error reporting slightly
Browse files Browse the repository at this point in the history
This cleans up the awkwardness I introduced in 5de1f8d and 78373d7.
  • Loading branch information
Vultraz committed Feb 15, 2021
1 parent 3671d3a commit d7eab68
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/server/campaignd/server.cpp
Expand Up @@ -215,35 +215,35 @@ bool have_wml(const utils::optional_reference<const config>& cfg)
*
* Null WML objects are skipped.
*/
bool multi_find_illegal_names(std::vector<std::string>& names, const std::vector<const config*>& indices)
template<typename... Vals>
std::optional<std::vector<std::string>> multi_find_illegal_names(const Vals&... items)
{
names.clear();
std::vector<std::string> names;
((items && check_names_legal(*items, &names)), ...);

for(auto* index : indices) {
if(index) {
check_names_legal(*index, &names);
}
if(!names.empty()) {
return names;
} else {
return std::nullopt;
}

return !names.empty();
}

/**
* Scans multiple WML pack-like trees for case conflicts.
*
* Null WML objects are skipped.
*/
bool multi_find_case_conflicts(std::vector<std::string>& names, const std::vector<const config*>& indices)
template<typename... Vals>
std::optional<std::vector<std::string>> multi_find_case_conflicts(const Vals&... items)
{
names.clear();
std::vector<std::string> names;
((items && check_case_insensitive_duplicates(*items, &names)), ...);

for(auto* index : indices) {
if(index) {
check_case_insensitive_duplicates(*index, &names);
}
if(!names.empty()) {
return names;
} else {
return std::nullopt;
}

return !names.empty();
}

/**
Expand Down Expand Up @@ -1304,17 +1304,15 @@ ADDON_CHECK_STATUS server::validate_addon(const server::request& req, config*& e
return ADDON_CHECK_STATUS::NO_EMAIL;
}

std::vector<std::string> badnames;

if(multi_find_illegal_names(badnames, {data.ptr(), addlist.ptr(), removelist.ptr()})) {
error_data = utils::join(badnames, "\n");
LOG_CS << "Validation error: invalid filenames in add-on pack (" << badnames.size() << " entries)\n";
if(const auto badnames = multi_find_illegal_names(data, addlist, removelist)) {
error_data = utils::join(*badnames, "\n");
LOG_CS << "Validation error: invalid filenames in add-on pack (" << badnames->size() << " entries)\n";
return ADDON_CHECK_STATUS::ILLEGAL_FILENAME;
}

if(multi_find_case_conflicts(badnames, {data.ptr(), addlist.ptr(), removelist.ptr()})) {
error_data = utils::join(badnames, "\n");
LOG_CS << "Validation error: case conflicts in add-on pack (" << badnames.size() << " entries)\n";
if(const auto badnames = multi_find_case_conflicts(data, addlist, removelist)) {
error_data = utils::join(*badnames, "\n");
LOG_CS << "Validation error: case conflicts in add-on pack (" << badnames->size() << " entries)\n";
return ADDON_CHECK_STATUS::FILENAME_CASE_CONFLICT;
}

Expand Down

0 comments on commit d7eab68

Please sign in to comment.