Redesigned error handling

Current error handling send only error code, which is not enough to
display detailed information. New error handling in additional to
error code send property name. This allows to send meaningful messages
back to used about errors.

Tested:
  - Old redfish code properly handles errors (reads only error_code)
  - Redfish version which read property name from error displays more
    detailed error information

Change-Id: I54caa20881ac3f3e38cb295a3aa95ddab491303f
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/src/utils/conversion.hpp b/src/utils/conversion.hpp
index fd3dbcb..e92249a 100644
--- a/src/utils/conversion.hpp
+++ b/src/utils/conversion.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "errors.hpp"
+
 #include <sdbusplus/exception.hpp>
 
 #include <algorithm>
@@ -10,24 +12,40 @@
 namespace utils
 {
 
-template <class T>
-struct EnumTraits
+template <size_t N>
+struct ConstexprString
 {
-    [[noreturn]] static void throwConversionError()
+    constexpr ConstexprString(const char (&data)[N]) : s()
     {
-        throw sdbusplus::exception::SdBusError(
-            static_cast<int>(std::errc::invalid_argument),
-            "Invalid enum value");
+        for (size_t i = 0; i < N; ++i)
+        {
+            s[i] = data[i];
+        }
     }
+
+    constexpr operator std::string_view() const
+    {
+        return {s.data(), s.size()};
+    }
+
+    std::array<char, N> s;
 };
 
+[[noreturn]] inline void throwConversionError(std::string_view propertyName)
+{
+    throw errors::InvalidArgument(propertyName, "Cannot convert.");
+}
+
+template <class T>
+struct EnumTraits;
+
 template <class T, T first, T last>
 inline T toEnum(std::underlying_type_t<T> x)
 {
     if (x < static_cast<std::underlying_type_t<T>>(first) ||
         x > static_cast<std::underlying_type_t<T>>(last))
     {
-        EnumTraits<T>::throwConversionError();
+        throwConversionError(EnumTraits<T>::propertyName);
     }
     return static_cast<T>(x);
 }
@@ -77,7 +95,7 @@
         [&value](const auto& item) { return item.first == value; });
     if (it == std::end(data))
     {
-        EnumTraits<T>::throwConversionError();
+        throwConversionError(EnumTraits<T>::propertyName);
     }
     return it->second;
 }
@@ -92,7 +110,7 @@
         [value](const auto& item) { return item.second == value; });
     if (it == std::end(data))
     {
-        EnumTraits<T>::throwConversionError();
+        throwConversionError(EnumTraits<T>::propertyName);
     }
     return it->first;
 }