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,6 +164,11 @@ auto load_config(std::string &cfg_file) -> app_config {
cfg.save(cfg_file); cfg.save(cfg_file);
} }
if (cfg.server_list.empty()) {
return cfg;
}
{
auto iter = std::ranges::adjacent_find( auto iter = std::ranges::adjacent_find(
cfg.server_list, cfg.server_list,
[](auto &&srv1, auto &&srv2) -> bool { return srv1.id == srv2.id; }); [](auto &&srv1, auto &&srv2) -> bool { return srv1.id == srv2.id; });
@ -174,6 +179,26 @@ auto load_config(std::string &cfg_file) -> app_config {
iter->id, 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;
} }