add a wrapper that always throws with a custom error message

use that wrapper for lokid.jsonrpc
pull/1306/head
Jeff Becker 4 years ago
parent a9109aa91b
commit a0dc2e795c
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -431,11 +431,19 @@ namespace llarp
conf.defineOption<bool>(
"lokid", "enabled", false, DefaultWhitelistRouters, AssignmentAcceptor(whitelistRouters));
auto setRPC = [this](std::string arg) { lokidRPCAddr = lokimq::address(arg); };
conf.defineOption<std::string>("lokid", "jsonrpc", false, DefaultLokidRPCAddr, setRPC);
conf.defineOption<std::string>(
"lokid",
"jsonrpc",
false,
"",
InvalidOption<std::string>("the [lokid]::jsonrpc option is deprecated please use the "
"[lokid]::rpc "
"config option instead"));
conf.defineOption<std::string>("lokid", "rpc", false, DefaultLokidRPCAddr, setRPC);
conf.defineOption<std::string>(
"lokid", "rpc", false, DefaultLokidRPCAddr, [this](std::string arg) {
lokidRPCAddr = lokimq::address(arg);
});
}
void

@ -448,4 +448,14 @@ namespace llarp
return [&](T arg) mutable { ref = std::move(arg); };
}
/// A wrapper that throws an invalid argument exception if the argument is provided in config
/// the invalid_arugment exception is constructed using a string that holds the exception's
/// message
template <typename T>
std::function<void(T)>
InvalidOption(std::string msg)
{
return [msg](T) mutable { throw std::invalid_argument(msg); };
}
} // namespace llarp

Loading…
Cancel
Save