Replace nfd::getExtendedErrorMessage with boost::diagnostic_information
Refs: #4834
Change-Id: I7fc00960d7e5a97748b2277c525a19775810377f
diff --git a/core/extended-error-message.hpp b/core/extended-error-message.hpp
deleted file mode 100644
index f1443bd..0000000
--- a/core/extended-error-message.hpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_CORE_EXTENDED_ERROR_MESSAGE_HPP
-#define NFD_CORE_EXTENDED_ERROR_MESSAGE_HPP
-
-#include <boost/exception/get_error_info.hpp>
-#include <sstream>
-
-namespace nfd {
-
-template<typename E>
-std::string
-getExtendedErrorMessage(const E& exception)
-{
- std::ostringstream errorMessage;
- errorMessage << exception.what();
-
- const char* const* file = boost::get_error_info<boost::throw_file>(exception);
- const int* line = boost::get_error_info<boost::throw_line>(exception);
- const char* const* func = boost::get_error_info<boost::throw_function>(exception);
- if (file && line) {
- errorMessage << " [from " << *file << ":" << *line;
- if (func) {
- errorMessage << " in " << *func;
- }
- errorMessage << "]";
- }
-
- return errorMessage.str();
-}
-
-} // namespace nfd
-
-#endif // NFD_CORE_EXTENDED_ERROR_MESSAGE_HPP
diff --git a/daemon/main.cpp b/daemon/main.cpp
index 5999ea1..f237a09 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,6 @@
#include "nfd.hpp"
#include "rib/service.hpp"
-#include "core/extended-error-message.hpp"
#include "core/global-io.hpp"
#include "core/logger.hpp"
#include "core/privilege-helper.hpp"
@@ -35,6 +34,7 @@
#include <string.h> // for strsignal()
#include <boost/config.hpp>
+#include <boost/exception/diagnostic_information.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
@@ -135,7 +135,7 @@
getGlobalIoService().run(); // ribIo is not thread-safe to use here
}
catch (const std::exception& e) {
- NFD_LOG_FATAL(e.what());
+ NFD_LOG_FATAL(boost::diagnostic_information(e));
retval = 1;
mainIo->stop();
}
@@ -158,7 +158,7 @@
mainIo->run();
}
catch (const std::exception& e) {
- NFD_LOG_FATAL(getExtendedErrorMessage(e));
+ NFD_LOG_FATAL(boost::diagnostic_information(e));
retval = 1;
}
catch (const PrivilegeHelper::Error& e) {
@@ -194,7 +194,7 @@
if (error)
return;
- NFD_LOG_INFO("Caught signal '" << ::strsignal(signalNo) << "', exiting...");
+ NFD_LOG_INFO("Caught signal " << signalNo << " (" << ::strsignal(signalNo) << "), exiting...");
systemdNotify("STOPPING=1");
getGlobalIoService().stop();
@@ -206,7 +206,7 @@
if (error)
return;
- NFD_LOG_INFO("Caught signal '" << ::strsignal(signalNo) << "', reloading...");
+ NFD_LOG_INFO("Caught signal " << signalNo << " (" << ::strsignal(signalNo) << "), reloading...");
systemdNotify("RELOADING=1");
m_nfd.reloadConfigFile();
@@ -321,18 +321,11 @@
runner.initialize();
}
catch (const boost::filesystem::filesystem_error& e) {
- if (e.code() == boost::system::errc::permission_denied) {
- NFD_LOG_FATAL("Permission denied for " << e.path1() <<
- ". This program should be run as superuser");
- return 4;
- }
- else {
- NFD_LOG_FATAL(getExtendedErrorMessage(e));
- return 1;
- }
+ NFD_LOG_FATAL(boost::diagnostic_information(e));
+ return e.code() == boost::system::errc::permission_denied ? 4 : 1;
}
catch (const std::exception& e) {
- NFD_LOG_FATAL(getExtendedErrorMessage(e));
+ NFD_LOG_FATAL(boost::diagnostic_information(e));
return 1;
}
catch (const PrivilegeHelper::Error& e) {
diff --git a/tests/limited-io.cpp b/tests/limited-io.cpp
index f31ec9c..a9da60e 100644
--- a/tests/limited-io.cpp
+++ b/tests/limited-io.cpp
@@ -24,10 +24,11 @@
*/
#include "limited-io.hpp"
-#include "core/extended-error-message.hpp"
#include "core/global-io.hpp"
#include "core/logger.hpp"
+#include <boost/exception/diagnostic_information.hpp>
+
namespace nfd {
namespace tests {
@@ -72,7 +73,7 @@
catch (const StopException&) {
}
catch (const std::exception& ex) {
- NFD_LOG_ERROR("g_io.run() exception: " << getExtendedErrorMessage(ex));
+ NFD_LOG_ERROR("LimitedIo::run: " << boost::diagnostic_information(ex));
m_reason = EXCEPTION;
m_lastException = std::current_exception();
}
diff --git a/tests/other/face-benchmark.cpp b/tests/other/face-benchmark.cpp
index 5745c03..19aac7c 100644
--- a/tests/other/face-benchmark.cpp
+++ b/tests/other/face-benchmark.cpp
@@ -23,12 +23,13 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/extended-error-message.hpp"
#include "core/global-io.hpp"
#include "face/face.hpp"
#include "face/tcp-channel.hpp"
#include "face/udp-channel.hpp"
+#include <boost/exception/diagnostic_information.hpp>
+
#include <fstream>
#include <iostream>
@@ -44,12 +45,16 @@
public:
FaceBenchmark(const char* configFileName)
: m_terminationSignalSet{getGlobalIoService()}
- , m_tcpChannel{tcp::Endpoint{boost::asio::ip::tcp::v4(), 6363}, false, bind([] { return ndn::nfd::FACE_SCOPE_NON_LOCAL; })}
+ , m_tcpChannel{tcp::Endpoint{boost::asio::ip::tcp::v4(), 6363}, false,
+ bind([] { return ndn::nfd::FACE_SCOPE_NON_LOCAL; })}
, m_udpChannel{udp::Endpoint{boost::asio::ip::udp::v4(), 6363}, time::minutes{10}, false}
{
m_terminationSignalSet.add(SIGINT);
m_terminationSignalSet.add(SIGTERM);
- m_terminationSignalSet.async_wait(bind(&FaceBenchmark::terminate, _1, _2));
+ m_terminationSignalSet.async_wait([] (const auto& error, int) {
+ if (!error)
+ getGlobalIoService().stop();
+ });
parseConfig(configFileName);
@@ -63,14 +68,6 @@
}
private:
- static void
- terminate(const boost::system::error_code& error, int signalNo)
- {
- if (error)
- return;
- getGlobalIoService().stop();
- }
-
void
parseConfig(const char* configFileName)
{
@@ -192,7 +189,7 @@
nfd::getGlobalIoService().run();
}
catch (const std::exception& e) {
- std::cerr << "FATAL: " << nfd::getExtendedErrorMessage(e) << std::endl;
+ std::cerr << "ERROR: " << boost::diagnostic_information(e);
return 1;
}
diff --git a/tests/rib-io-fixture.cpp b/tests/rib-io-fixture.cpp
index d058851..91fc979 100644
--- a/tests/rib-io-fixture.cpp
+++ b/tests/rib-io-fixture.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,8 +24,8 @@
*/
#include "rib-io-fixture.hpp"
-#include "core/extended-error-message.hpp"
-#include <iostream>
+
+#include <boost/exception/diagnostic_information.hpp>
namespace nfd {
namespace tests {
@@ -72,9 +72,9 @@
m_ribPollEndCv.notify_all();
}
}
- catch (const std::exception& e) {
- std::cerr << "Exception in RIB thread: " << getExtendedErrorMessage(e) << std::endl;
- throw;
+ catch (...) {
+ BOOST_WARN_MESSAGE(false, boost::current_exception_diagnostic_information());
+ NDN_THROW_NESTED(std::runtime_error("Fatal exception in RIB thread"));
}
});
diff --git a/tools/ndn-autoconfig-server/main.cpp b/tools/ndn-autoconfig-server/main.cpp
index 1077a8d..c281148 100644
--- a/tools/ndn-autoconfig-server/main.cpp
+++ b/tools/ndn-autoconfig-server/main.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2017, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,12 +24,13 @@
*/
#include "program.hpp"
-#include "core/extended-error-message.hpp"
#include "core/version.hpp"
#include <iostream>
#include <unistd.h>
+#include <boost/exception/diagnostic_information.hpp>
+
namespace ndn {
namespace tools {
namespace autoconfig_server {
@@ -42,8 +43,8 @@
<< "Options:\n"
<< " -h - print usage and exit\n"
<< " -V - print version number and exit\n"
- << " -p prefix - a local prefix of the HUB\n"
- << " hub-face - a FaceUri to reach the HUB\n";
+ << " -p prefix - a local prefix of the hub\n"
+ << " hub-face - a FaceUri to reach the hub\n";
}
static int
@@ -75,7 +76,7 @@
}
if (!options.hubFaceUri.parse(argv[::optind])) {
- std::cerr << "ERROR: cannot parse HUB FaceUri" << std::endl;
+ std::cerr << "ERROR: cannot parse hub FaceUri" << std::endl;
return 2;
}
@@ -86,7 +87,7 @@
program.run();
}
catch (const std::exception& e) {
- std::cerr << ::nfd::getExtendedErrorMessage(e) << std::endl;
+ std::cerr << "ERROR: " << boost::diagnostic_information(e);
return 1;
}
return 0;
diff --git a/tools/ndn-autoconfig/main.cpp b/tools/ndn-autoconfig/main.cpp
index a8b2c45..dd7bec6 100644
--- a/tools/ndn-autoconfig/main.cpp
+++ b/tools/ndn-autoconfig/main.cpp
@@ -24,15 +24,17 @@
*/
#include "procedure.hpp"
-#include "core/extended-error-message.hpp"
#include "core/scheduler.hpp"
#include "core/version.hpp"
#include <signal.h>
#include <string.h>
+
+#include <boost/exception/diagnostic_information.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
+
#include <ndn-cxx/net/network-monitor.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/time.hpp>
@@ -48,9 +50,9 @@
namespace tools {
namespace autoconfig {
-static const time::nanoseconds DAEMON_INITIAL_DELAY = time::milliseconds(100);
-static const time::nanoseconds DAEMON_UNCONDITIONAL_INTERVAL = time::hours(1);
-static const time::nanoseconds NETMON_DAMPEN_PERIOD = time::seconds(5);
+static const time::nanoseconds DAEMON_INITIAL_DELAY = 100_ms;
+static const time::nanoseconds DAEMON_UNCONDITIONAL_INTERVAL = 1_h;
+static const time::nanoseconds NETMON_DAMPEN_PERIOD = 5_s;
namespace po = boost::program_options;
@@ -181,7 +183,7 @@
}
}
catch (const std::exception& e) {
- std::cerr << ::nfd::getExtendedErrorMessage(e) << std::endl;
+ std::cerr << "ERROR: " << boost::diagnostic_information(e);
return 1;
}
diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp
index cd3f093..fed9cfb 100644
--- a/tools/nfd-autoreg.cpp
+++ b/tools/nfd-autoreg.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,7 +23,6 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/extended-error-message.hpp"
#include "core/network.hpp"
#include "core/version.hpp"
@@ -36,6 +35,7 @@
#include <ndn-cxx/net/face-uri.hpp>
#include <ndn-cxx/security/key-chain.hpp>
+#include <boost/exception/diagnostic_information.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>
@@ -277,7 +277,7 @@
startProcessing();
}
catch (const std::exception& e) {
- std::cerr << "ERROR: " << ::nfd::getExtendedErrorMessage(e) << std::endl;
+ std::cerr << "ERROR: " << boost::diagnostic_information(e);
return 1;
}