summaryrefslogtreecommitdiffstats
path: root/phosphor-logging
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-03-09 23:50:43 -0600
committerPatrick Williams <patrick@stwcx.xyz>2017-03-15 21:11:40 +0000
commit153311005f6c4f0de710adebaf93a98cc2ca8ebc (patch)
tree2032a8d03490b8a7c4dd56691188385d5fcf5676 /phosphor-logging
parent682326a19c45b68299cb295b69754a9eb3154f48 (diff)
downloadphosphor-logging-153311005f6c4f0de710adebaf93a98cc2ca8ebc.tar.gz
phosphor-logging-153311005f6c4f0de710adebaf93a98cc2ca8ebc.zip
Map sdbusplus exception to phosphor exception
Errors will be created by using the sdbusplus error types, which results in an sdbusplus exception being thrown. Error metadata can be verified at compile-time by checking the error against phosphor-logging error types. This commit maps the sdbusplus error type to the phosphor type, for this purpose, via template specializations. Change-Id: Iee37e2a3846cc3acf3a62270a520ff0c395fd36d Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'phosphor-logging')
-rw-r--r--phosphor-logging/elog.hpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/phosphor-logging/elog.hpp b/phosphor-logging/elog.hpp
index fe79bdc..329dc0d 100644
--- a/phosphor-logging/elog.hpp
+++ b/phosphor-logging/elog.hpp
@@ -3,7 +3,6 @@
#include <tuple>
#include <utility>
#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog-errors.hpp>
namespace phosphor
{
@@ -65,26 +64,27 @@ struct deduce_entry_type<prev_entry<T>>
template <typename T> using deduce_entry_type_t =
typename deduce_entry_type<T>::type;
-} // namespace details
-
/**
- * @brief Error log exception base class
+ * @brief Used to map an sdbusplus error to a phosphor-logging error type
*
- * This allows people to capture all error log exceptions if desired
+ * Users log errors via the sdbusplus error name, and the execption that's
+ * thrown is the corresponding sdbusplus exception. However, there's a need
+ * to map the sdbusplus error name to the phosphor-logging error name, in order
+ * to verify the error metadata at compile-time.
*/
-class elogExceptionBase : public std::exception {};
+template <typename T>
+struct map_exception_type
+{
+ using type = T;
+};
/**
- * @brief Error log exception class
- *
- * This is for capturing specific error log exceptions
+ * @brief Typedef for above structure usage
*/
-template <typename T> class elogException : public elogExceptionBase
-{
- public:
- const char* what() const noexcept override { return T::err_code; }
- const char* name() const noexcept { return T::err_code; }
-};
+template <typename T> using map_exception_type_t =
+ typename map_exception_type<T>::type;
+
+} // namespace details
/** @fn commit()
* @brief Create an error log entry based on journal
@@ -103,17 +103,19 @@ template <typename T, typename ...Args>
void elog(Args... i_args)
{
// Validate the caller passed in the required parameters
- static_assert(std::is_same<typename T::metadata_types,
+ static_assert(std::is_same<typename details::
+ map_exception_type_t<T>::metadata_types,
std::tuple<
details::deduce_entry_type_t<Args>...>>
::value,
"You are not passing in required arguments for this error");
- log<T::L>(T::err_msg,
- details::deduce_entry_type<Args>{i_args}.get()...);
+ log<details::map_exception_type_t<T>::L>(
+ details::map_exception_type_t<T>::err_msg,
+ details::deduce_entry_type<Args>{i_args}.get()...);
// Now throw an exception for this error
- throw elogException<T>();
+ throw T();
}
} // namespace logging
OpenPOWER on IntegriCloud