Handle invalid enum value in convertForMessage()

The function convertForMessage() takes an enum class as input, and it
assume the enum value is valid and does not check the return value of
std::find_if().

If user deliberately passes an invalid enum value, it causes undefined
behavior.

Handle this case by checking the return value and throw
std::invalid_argument if the input argument is invalid.

Tested: Verify the unit test in phosphor-time-manager passed; without
        the fix, the test fails when -flto is enabled.

Change-Id: I3874eaeb44b8e89469690a21090005d299d0f4b1
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp.in b/tools/sdbusplus/templates/interface.mako.server.cpp.in
index c8d5f65..0043f75 100644
--- a/tools/sdbusplus/templates/interface.mako.server.cpp.in
+++ b/tools/sdbusplus/templates/interface.mako.server.cpp.in
@@ -125,6 +125,10 @@
             std::begin(mapping${classname}${e.name}),
             std::end(mapping${classname}${e.name}),
             [v](auto& e){ return v == std::get<1>(e); });
+    if (i == std::end(mapping${classname}${e.name}))
+    {
+        throw std::invalid_argument(std::to_string(static_cast<int>(v)));
+    }
     return std::get<0>(*i);
 }
     % endfor