throw error on invalid id name

This commit is contained in:
Scott E. Graves 2025-02-20 18:26:44 -06:00
parent ba54e4d02e
commit 37ca295f41
2 changed files with 35 additions and 9 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ scripts/cleanup.sh
support/Dockerfile support/Dockerfile
version.cpp version.cpp
version.rc version.rc
monitarr.json

View File

@ -164,15 +164,40 @@ auto load_config(std::string &cfg_file) -> app_config {
cfg.save(cfg_file); cfg.save(cfg_file);
} }
auto iter = std::ranges::adjacent_find( if (cfg.server_list.empty()) {
cfg.server_list, return cfg;
[](auto &&srv1, auto &&srv2) -> bool { return srv1.id == srv2.id; }); }
if (iter != cfg.server_list.end()) {
throw utils::error::create_exception(function_name, {
{ auto iter = std::ranges::adjacent_find(
"duplicate server found", cfg.server_list,
iter->id, [](auto &&srv1, auto &&srv2) -> bool { return srv1.id == srv2.id; });
}); if (iter != cfg.server_list.end()) {
throw utils::error::create_exception(function_name,
{
"duplicate server found",
iter->id,
});
}
}
{
constexpr const auto id_names{
std::array<std::string_view, 3U>{"lidarr", "radarr", "sonarr"},
};
auto iter = std::ranges::find_first_of(
cfg.server_list, id_names, [](auto &&data, auto &&name) -> bool {
return utils::string::contains(data.id, name);
});
if (iter == cfg.server_list.end()) {
throw utils::error::create_exception(
function_name,
{
"server id must contain one of the following values",
fmt::format("{}", id_names),
});
}
} }
return cfg; return cfg;