From 03c9c10d0ce5eddefe48a6033f570e4a77579de9 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Thu, 22 Jul 2021 22:02:41 +0300 Subject: [PATCH] [#1077] netconf: throw, don't exit --- src/bin/netconf/netconf.cc | 17 ++++++----------- src/bin/netconf/netconf.h | 1 - src/bin/netconf/netconf_cfg_mgr.cc | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/bin/netconf/netconf.cc b/src/bin/netconf/netconf.cc index 780db0ed36..ddb3a6a961 100644 --- a/src/bin/netconf/netconf.cc +++ b/src/bin/netconf/netconf.cc @@ -272,19 +272,17 @@ void NetconfAgent::getModules() { S_Context context(running_sess_->get_context()); modules = context->get_module_iter(); } catch (const sysrepo_exception& ex) { - cerr << "ERROR: Can't retrieve available modules: " << ex.what() << endl; - exit(1); + isc_throw(Unexpected, "can't retrieve available modules: " << ex.what()); } for (S_Module const& module : modules) { if (!module->name()) { - cerr << "ERROR: module name is mangled" << endl; - exit(2); + isc_throw(Unexpected, "could not retrieve module name"); } string const name(module->name()); if (!module->rev() || !module->rev()->date()) { - cerr << "ERROR: module revision is mangled" << endl; - exit(3); + isc_throw(Unexpected, + "could not retrieve module revision for module " << name); } string const revision(module->rev()->date()); modules_.emplace(name, revision); @@ -328,11 +326,8 @@ NetconfAgent::checkModules(CfgServersMapPtr const& servers /* = {} */) const { } if (faulty_model) { - cerr << "ERROR: The logged YANG module is missing or its revision is not " - "supported. The environment is not suitable for running " - "kea-netconf." - << endl; - exit(4); + isc_throw(Unexpected, "YANG module is missing or its revision is not " + "supported. Check logs for details."); } for (auto modrev : YANG_REVISIONS) { diff --git a/src/bin/netconf/netconf.h b/src/bin/netconf/netconf.h index b28659472b..d8cfc37611 100644 --- a/src/bin/netconf/netconf.h +++ b/src/bin/netconf/netconf.h @@ -107,7 +107,6 @@ protected: /// /// Emit a fatal error if an essential one (i.e. required in /// a further phase) is missing or does not have the expected revision. - /// The caller (init) will exit(). /// /// @param module_name The module name. /// @return true if available, false if not. diff --git a/src/bin/netconf/netconf_cfg_mgr.cc b/src/bin/netconf/netconf_cfg_mgr.cc index 1f889a73d5..82a19f2fe7 100644 --- a/src/bin/netconf/netconf_cfg_mgr.cc +++ b/src/bin/netconf/netconf_cfg_mgr.cc @@ -90,7 +90,7 @@ NetconfCfgMgr::parse(isc::data::ConstElementPtr config_set, bool check_only) { // Do a sanity check first. if (!config_set) { - isc_throw(DhcpConfigError, "Mandatory config parameter not provided"); + isc_throw(ConfigError, "Mandatory config parameter not provided"); } NetconfConfigPtr ctx = getNetconfConfig();