mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
add a wrapper that always throws with a custom error message
use that wrapper for lokid.jsonrpc
This commit is contained in:
parent
a9109aa91b
commit
a0dc2e795c
|
@ -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,
|
||||
"",
|
||||
InvalidOption<std::string>("the [lokid]::jsonrpc option is deprecated please use the "
|
||||
"[lokid]::rpc "
|
||||
"config option instead"));
|
||||
|
||||
conf.defineOption<std::string>("lokid", "jsonrpc", false, DefaultLokidRPCAddr, setRPC);
|
||||
|
||||
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…
Reference in a new issue