throw error on invalid id name
This commit is contained in:
parent
ba54e4d02e
commit
37ca295f41
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@ scripts/cleanup.sh
|
|||||||
support/Dockerfile
|
support/Dockerfile
|
||||||
version.cpp
|
version.cpp
|
||||||
version.rc
|
version.rc
|
||||||
|
monitarr.json
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user