From a0dc2e795c5eef1aa44f4d289b0c27a8738d49c8 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 30 Jun 2020 14:08:19 -0400 Subject: [PATCH] add a wrapper that always throws with a custom error message use that wrapper for lokid.jsonrpc --- llarp/config/config.cpp | 16 ++++++++++++---- llarp/config/definition.hpp | 10 ++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 849c545f1..30cc9a9b5 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -431,11 +431,19 @@ namespace llarp conf.defineOption( "lokid", "enabled", false, DefaultWhitelistRouters, AssignmentAcceptor(whitelistRouters)); - auto setRPC = [this](std::string arg) { lokidRPCAddr = lokimq::address(arg); }; - - conf.defineOption("lokid", "jsonrpc", false, DefaultLokidRPCAddr, setRPC); + conf.defineOption( + "lokid", + "jsonrpc", + false, + "", + InvalidOption("the [lokid]::jsonrpc option is deprecated please use the " + "[lokid]::rpc " + "config option instead")); - conf.defineOption("lokid", "rpc", false, DefaultLokidRPCAddr, setRPC); + conf.defineOption( + "lokid", "rpc", false, DefaultLokidRPCAddr, [this](std::string arg) { + lokidRPCAddr = lokimq::address(arg); + }); } void diff --git a/llarp/config/definition.hpp b/llarp/config/definition.hpp index f58f91d4d..394b2aead 100644 --- a/llarp/config/definition.hpp +++ b/llarp/config/definition.hpp @@ -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 + std::function + InvalidOption(std::string msg) + { + return [msg](T) mutable { throw std::invalid_argument(msg); }; + } + } // namespace llarp