Throw instead of asserting giving the user the ability to handle the error more gracefully.
Also replace tab with spaces.
#include <vespa/fnet/frt/target.h>
#include <vespa/vespalib/util/host_name.h>
#include <vespa/vespalib/stllike/asciistream.h>
+#include <vespa/vespalib/util/exceptions.h>
#include <sstream>
#include <vespa/log/log.h>
LOG_SETUP(".slobrok.register");
+using vespalib::IllegalStateException;
+
namespace {
vespalib::string
@@ -47,8 +50,7 @@ discard(std::vector<vespalib::string> &vec, const vespalib::stringref & val)
} // namespace <unnamed>
-namespace slobrok {
-namespace api {
+namespace slobrok::api {
RegisterAPI::RegisterAPI(FRT_Supervisor &orb, const ConfiguratorFactory & config)
: FNET_Task(orb.GetScheduler()),
@@ -69,6 +71,10 @@ RegisterAPI::RegisterAPI(FRT_Supervisor &orb, const ConfiguratorFactory & config
_req(0)
{
_configurator->poll();
+ if ( ! _slobrokSpecs.ok()) {
+ throw IllegalStateException("Failed configuring the RegisterAPI. No valid slobrok specs from config",
+ VESPA_STRLOC);
+ }
LOG_ASSERT(_slobrokSpecs.ok());
ScheduleNow();
}
@@ -312,5 +318,4 @@ RegisterAPI::RPCHooks::rpc_notifyUnregistered(FRT_RPCRequest *req)
LOG(warning, "unregistered name %s", args[0]._string._str);
}
-} // namespace api
-} // namespace slobrok
+}
