2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-01-02 12:06:00 +01:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
|
2012-05-10 12:06:41 +02:00
|
|
|
* *
|
|
|
|
* This program 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 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation *
|
2012-05-11 13:33:57 +02:00
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
2012-05-10 12:06:41 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/exception.hpp"
|
2012-04-03 13:01:00 +02:00
|
|
|
|
2014-09-02 13:02:22 +02:00
|
|
|
#ifdef HAVE_CXXABI_H
|
2014-04-20 14:09:01 +02:00
|
|
|
# include <cxxabi.h>
|
2014-09-02 13:02:22 +02:00
|
|
|
#endif /* HAVE_CXXABI_H */
|
2014-04-20 14:09:01 +02:00
|
|
|
|
2012-04-03 13:01:00 +02:00
|
|
|
using namespace icinga;
|
|
|
|
|
2013-11-19 07:49:41 +01:00
|
|
|
static boost::thread_specific_ptr<StackTrace> l_LastExceptionStack;
|
|
|
|
static boost::thread_specific_ptr<ContextTrace> l_LastExceptionContext;
|
2013-03-07 19:44:39 +01:00
|
|
|
|
2014-09-02 13:02:22 +02:00
|
|
|
#ifdef HAVE_CXXABI_H
|
2016-08-30 20:02:47 +02:00
|
|
|
|
|
|
|
#ifdef _LIBCPPABI_VERSION
|
|
|
|
class libcxx_type_info : public std::type_info
|
|
|
|
{
|
|
|
|
public:
|
2018-01-04 05:12:56 +01:00
|
|
|
~libcxx_type_info() override;
|
2016-08-30 20:02:47 +02:00
|
|
|
|
|
|
|
virtual void noop1() const;
|
|
|
|
virtual void noop2() const;
|
|
|
|
virtual bool can_catch(const libcxx_type_info *thrown_type, void *&adjustedPtr) const = 0;
|
|
|
|
};
|
|
|
|
#endif /* _LIBCPPABI_VERSION */
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__GLIBCXX__) || defined(_LIBCPPABI_VERSION)
|
|
|
|
inline void *cast_exception(void *obj, const std::type_info *src, const std::type_info *dst)
|
|
|
|
{
|
|
|
|
#ifdef __GLIBCXX__
|
|
|
|
void *thrown_ptr = obj;
|
|
|
|
|
|
|
|
/* Check if the exception is a pointer type. */
|
|
|
|
if (src->__is_pointer_p())
|
|
|
|
thrown_ptr = *(void **)thrown_ptr;
|
|
|
|
|
|
|
|
if (dst->__do_catch(src, &thrown_ptr, 1))
|
|
|
|
return thrown_ptr;
|
|
|
|
else
|
2017-12-14 15:37:20 +01:00
|
|
|
return nullptr;
|
2016-08-30 20:02:47 +02:00
|
|
|
#else /* __GLIBCXX__ */
|
2018-01-04 09:07:03 +01:00
|
|
|
const auto *srcInfo = static_cast<const libcxx_type_info *>(src);
|
|
|
|
const auto *dstInfo = static_cast<const libcxx_type_info *>(dst);
|
2016-08-30 20:02:47 +02:00
|
|
|
|
|
|
|
void *adj = obj;
|
|
|
|
|
|
|
|
if (dstInfo->can_catch(srcInfo, adj))
|
|
|
|
return adj;
|
|
|
|
else
|
2017-12-14 15:37:20 +01:00
|
|
|
return nullptr;
|
2016-08-30 20:02:47 +02:00
|
|
|
#endif /* __GLIBCXX__ */
|
|
|
|
|
|
|
|
}
|
|
|
|
#else /* defined(__GLIBCXX__) || defined(_LIBCPPABI_VERSION) */
|
|
|
|
#define NO_CAST_EXCEPTION
|
|
|
|
#endif /* defined(__GLIBCXX__) || defined(_LIBCPPABI_VERSION) */
|
|
|
|
|
2014-04-22 07:13:16 +02:00
|
|
|
# if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ > 3)
|
|
|
|
# define TYPEINFO_TYPE std::type_info
|
|
|
|
# else
|
|
|
|
# define TYPEINFO_TYPE void
|
|
|
|
# endif
|
|
|
|
|
2014-09-02 13:02:22 +02:00
|
|
|
# if !defined(__GLIBCXX__) && !defined(_WIN32)
|
2014-04-14 03:02:33 +02:00
|
|
|
static boost::thread_specific_ptr<void *> l_LastExceptionObj;
|
2014-04-22 07:13:16 +02:00
|
|
|
static boost::thread_specific_ptr<TYPEINFO_TYPE *> l_LastExceptionPvtInfo;
|
2014-04-14 03:02:33 +02:00
|
|
|
|
|
|
|
typedef void (*DestCallback)(void *);
|
|
|
|
static boost::thread_specific_ptr<DestCallback> l_LastExceptionDest;
|
2014-09-02 13:02:22 +02:00
|
|
|
# endif /* !__GLIBCXX__ && !_WIN32 */
|
2016-08-30 20:02:47 +02:00
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
extern "C" void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *));
|
2014-09-02 13:02:22 +02:00
|
|
|
#endif /* HAVE_CXXABI_H */
|
2014-04-14 03:02:33 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void icinga::RethrowUncaughtException()
|
2014-04-14 03:02:33 +02:00
|
|
|
{
|
2016-08-31 13:24:57 +02:00
|
|
|
#if defined(__GLIBCXX__) || !defined(HAVE_CXXABI_H)
|
2014-04-14 03:02:33 +02:00
|
|
|
throw;
|
2016-08-31 13:24:57 +02:00
|
|
|
#else /* __GLIBCXX__ || !HAVE_CXXABI_H */
|
2014-04-14 03:02:33 +02:00
|
|
|
__cxa_throw(*l_LastExceptionObj.get(), *l_LastExceptionPvtInfo.get(), *l_LastExceptionDest.get());
|
2016-08-31 13:24:57 +02:00
|
|
|
#endif /* __GLIBCXX__ || !HAVE_CXXABI_H */
|
2014-04-14 03:02:33 +02:00
|
|
|
}
|
|
|
|
|
2014-09-02 13:02:22 +02:00
|
|
|
#ifdef HAVE_CXXABI_H
|
2013-03-07 19:44:39 +01:00
|
|
|
extern "C"
|
2014-04-20 14:09:01 +02:00
|
|
|
void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *))
|
2013-03-07 19:44:39 +01:00
|
|
|
{
|
2018-01-04 09:07:03 +01:00
|
|
|
auto *tinfo = static_cast<std::type_info *>(pvtinfo);
|
2014-04-20 14:09:01 +02:00
|
|
|
|
|
|
|
typedef void (*cxa_throw_fn)(void *, std::type_info *, void (*)(void *)) __attribute__((noreturn));
|
2013-03-07 19:44:39 +01:00
|
|
|
static cxa_throw_fn real_cxa_throw;
|
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
#if !defined(__GLIBCXX__) && !defined(_WIN32)
|
2014-04-14 03:02:33 +02:00
|
|
|
l_LastExceptionObj.reset(new void *(obj));
|
2014-04-22 07:13:16 +02:00
|
|
|
l_LastExceptionPvtInfo.reset(new TYPEINFO_TYPE *(pvtinfo));
|
2014-04-14 03:02:33 +02:00
|
|
|
l_LastExceptionDest.reset(new DestCallback(dest));
|
2016-08-30 20:02:47 +02:00
|
|
|
#endif /* !defined(__GLIBCXX__) && !defined(_WIN32) */
|
2014-04-14 03:02:33 +02:00
|
|
|
|
2018-01-04 09:18:50 +01:00
|
|
|
if (real_cxa_throw == nullptr)
|
2013-03-07 19:44:39 +01:00
|
|
|
real_cxa_throw = (cxa_throw_fn)dlsym(RTLD_NEXT, "__cxa_throw");
|
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
#ifndef NO_CAST_EXCEPTION
|
|
|
|
void *uex = cast_exception(obj, tinfo, &typeid(user_error));
|
2018-01-04 09:07:03 +01:00
|
|
|
auto *ex = reinterpret_cast<boost::exception *>(cast_exception(obj, tinfo, &typeid(boost::exception)));
|
2013-03-07 19:44:39 +01:00
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
if (!uex) {
|
|
|
|
#endif /* NO_CAST_EXCEPTION */
|
2014-03-22 08:38:46 +01:00
|
|
|
StackTrace stack;
|
|
|
|
SetLastExceptionStack(stack);
|
2013-11-19 07:49:41 +01:00
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
#ifndef NO_CAST_EXCEPTION
|
2017-12-14 15:37:20 +01:00
|
|
|
if (ex && !boost::get_error_info<StackTraceErrorInfo>(*ex))
|
2016-08-30 20:02:47 +02:00
|
|
|
*ex << StackTraceErrorInfo(stack);
|
|
|
|
}
|
|
|
|
#endif /* NO_CAST_EXCEPTION */
|
2013-03-08 14:41:01 +01:00
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
ContextTrace context;
|
|
|
|
SetLastExceptionContext(context);
|
2013-03-07 19:44:39 +01:00
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
#ifndef NO_CAST_EXCEPTION
|
2017-12-14 15:37:20 +01:00
|
|
|
if (ex && !boost::get_error_info<ContextTraceErrorInfo>(*ex))
|
2016-08-30 20:02:47 +02:00
|
|
|
*ex << ContextTraceErrorInfo(context);
|
|
|
|
#endif /* NO_CAST_EXCEPTION */
|
2013-03-07 19:44:39 +01:00
|
|
|
|
2014-04-20 14:09:01 +02:00
|
|
|
real_cxa_throw(obj, tinfo, dest);
|
2013-03-07 19:44:39 +01:00
|
|
|
}
|
2014-09-02 13:02:22 +02:00
|
|
|
#endif /* HAVE_CXXABI_H */
|
2013-03-07 19:44:39 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
StackTrace *icinga::GetLastExceptionStack()
|
2013-03-07 19:44:39 +01:00
|
|
|
{
|
2013-11-19 07:49:41 +01:00
|
|
|
return l_LastExceptionStack.get();
|
2013-03-07 19:44:39 +01:00
|
|
|
}
|
|
|
|
|
2013-11-20 21:55:14 +01:00
|
|
|
void icinga::SetLastExceptionStack(const StackTrace& trace)
|
2013-03-07 19:44:39 +01:00
|
|
|
{
|
2013-11-19 07:49:41 +01:00
|
|
|
l_LastExceptionStack.reset(new StackTrace(trace));
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ContextTrace *icinga::GetLastExceptionContext()
|
2013-11-19 07:49:41 +01:00
|
|
|
{
|
|
|
|
return l_LastExceptionContext.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void icinga::SetLastExceptionContext(const ContextTrace& context)
|
|
|
|
{
|
|
|
|
l_LastExceptionContext.reset(new ContextTrace(context));
|
2013-11-20 21:55:14 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, StackTrace *stack, ContextTrace *context)
|
|
|
|
{
|
|
|
|
std::ostringstream result;
|
|
|
|
|
|
|
|
String message = ex.what();
|
|
|
|
|
2018-01-04 09:07:03 +01:00
|
|
|
const auto *vex = dynamic_cast<const ValidationError *>(&ex);
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2014-12-20 15:41:31 +01:00
|
|
|
if (message.IsEmpty())
|
2015-11-10 17:04:49 +01:00
|
|
|
result << boost::diagnostic_information(ex) << "\n";
|
2014-12-20 15:29:04 +01:00
|
|
|
else
|
2015-11-10 17:04:49 +01:00
|
|
|
result << "Error: " << message << "\n";
|
2014-12-20 15:29:04 +01:00
|
|
|
|
2018-01-04 09:07:03 +01:00
|
|
|
const auto *dex = dynamic_cast<const ScriptError *>(&ex);
|
2014-12-20 15:29:04 +01:00
|
|
|
|
2015-11-10 17:04:49 +01:00
|
|
|
if (dex && !dex->GetDebugInfo().Path.IsEmpty())
|
|
|
|
ShowCodeLocation(result, dex->GetDebugInfo());
|
2014-12-20 15:29:04 +01:00
|
|
|
|
2014-11-30 23:32:13 +01:00
|
|
|
if (vex) {
|
|
|
|
DebugInfo di;
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr dobj = vex->GetObject();
|
2014-11-30 23:32:13 +01:00
|
|
|
if (dobj)
|
|
|
|
di = dobj->GetDebugInfo();
|
|
|
|
|
|
|
|
Dictionary::Ptr currentHint = vex->GetDebugHint();
|
|
|
|
Array::Ptr messages;
|
|
|
|
|
2015-08-13 08:52:00 +02:00
|
|
|
if (currentHint) {
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const String& attr : vex->GetAttributePath()) {
|
2015-08-13 08:52:00 +02:00
|
|
|
Dictionary::Ptr props = currentHint->Get("properties");
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2015-08-13 08:52:00 +02:00
|
|
|
if (!props)
|
|
|
|
break;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2015-08-13 08:52:00 +02:00
|
|
|
currentHint = props->Get(attr);
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2015-08-13 08:52:00 +02:00
|
|
|
if (!currentHint)
|
|
|
|
break;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2015-08-13 08:52:00 +02:00
|
|
|
messages = currentHint->Get("messages");
|
|
|
|
}
|
2014-11-30 23:32:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (messages && messages->GetLength() > 0) {
|
|
|
|
Array::Ptr message = messages->Get(messages->GetLength() - 1);
|
|
|
|
|
|
|
|
di.Path = message->Get(1);
|
|
|
|
di.FirstLine = message->Get(2);
|
|
|
|
di.FirstColumn = message->Get(3);
|
|
|
|
di.LastLine = message->Get(4);
|
|
|
|
di.LastColumn = message->Get(5);
|
|
|
|
}
|
|
|
|
|
2015-11-10 17:04:49 +01:00
|
|
|
if (!di.Path.IsEmpty())
|
|
|
|
ShowCodeLocation(result, di);
|
2014-11-30 23:32:13 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 09:07:03 +01:00
|
|
|
const auto *uex = dynamic_cast<const user_error *>(&ex);
|
|
|
|
const auto *pex = dynamic_cast<const posix_error *>(&ex);
|
2014-12-20 15:29:04 +01:00
|
|
|
|
2015-01-12 12:36:49 +01:00
|
|
|
if (!uex && !pex && verbose) {
|
2014-12-20 15:29:04 +01:00
|
|
|
const StackTrace *st = boost::get_error_info<StackTraceErrorInfo>(ex);
|
|
|
|
|
|
|
|
if (st) {
|
|
|
|
result << *st;
|
|
|
|
} else {
|
|
|
|
result << std::endl;
|
|
|
|
|
|
|
|
if (!stack)
|
|
|
|
stack = GetLastExceptionStack();
|
|
|
|
|
|
|
|
if (stack)
|
|
|
|
result << *stack;
|
|
|
|
|
|
|
|
}
|
2016-08-30 20:02:47 +02:00
|
|
|
}
|
2014-12-20 15:29:04 +01:00
|
|
|
|
2016-08-30 20:12:35 +02:00
|
|
|
const ContextTrace *ct = boost::get_error_info<ContextTraceErrorInfo>(ex);
|
|
|
|
|
|
|
|
if (ct) {
|
|
|
|
result << *ct;
|
|
|
|
} else {
|
2016-08-30 20:02:47 +02:00
|
|
|
result << std::endl;
|
2014-12-20 15:29:04 +01:00
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
if (!context)
|
|
|
|
context = GetLastExceptionContext();
|
2014-12-20 15:29:04 +01:00
|
|
|
|
2016-08-30 20:02:47 +02:00
|
|
|
if (context)
|
|
|
|
result << *context;
|
2014-12-20 15:29:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result.str();
|
|
|
|
}
|
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
String icinga::DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose)
|
2013-11-20 21:55:14 +01:00
|
|
|
{
|
|
|
|
StackTrace *pt = GetLastExceptionStack();
|
2013-11-19 07:49:41 +01:00
|
|
|
StackTrace stack;
|
|
|
|
|
|
|
|
ContextTrace *pc = GetLastExceptionContext();
|
|
|
|
ContextTrace context;
|
2013-11-20 21:55:14 +01:00
|
|
|
|
|
|
|
if (pt)
|
2013-11-19 07:49:41 +01:00
|
|
|
stack = *pt;
|
|
|
|
|
|
|
|
if (pc)
|
|
|
|
context = *pc;
|
2013-11-20 21:55:14 +01:00
|
|
|
|
|
|
|
try {
|
2016-08-31 13:43:14 +02:00
|
|
|
boost::rethrow_exception(eptr);
|
2013-11-20 21:55:14 +01:00
|
|
|
} catch (const std::exception& ex) {
|
2017-12-14 15:37:20 +01:00
|
|
|
return DiagnosticInformation(ex, verbose, pt ? &stack : nullptr, pc ? &context : nullptr);
|
2013-11-20 21:55:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return boost::diagnostic_information(eptr);
|
2013-03-07 19:44:39 +01:00
|
|
|
}
|
2014-05-22 14:41:27 +02:00
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
ScriptError::ScriptError(String message)
|
|
|
|
: m_Message(std::move(message)), m_IncompleteExpr(false)
|
2014-12-18 15:11:57 +01:00
|
|
|
{ }
|
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
ScriptError::ScriptError(String message, DebugInfo di, bool incompleteExpr)
|
|
|
|
: m_Message(std::move(message)), m_DebugInfo(std::move(di)), m_IncompleteExpr(incompleteExpr), m_HandledByDebugger(false)
|
2014-12-18 15:11:57 +01:00
|
|
|
{ }
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
const char *ScriptError::what() const throw()
|
2014-12-18 15:11:57 +01:00
|
|
|
{
|
|
|
|
return m_Message.CStr();
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
DebugInfo ScriptError::GetDebugInfo() const
|
2014-12-18 15:11:57 +01:00
|
|
|
{
|
|
|
|
return m_DebugInfo;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
bool ScriptError::IsIncompleteExpression() const
|
2015-02-10 13:27:02 +01:00
|
|
|
{
|
2018-01-24 12:07:52 +01:00
|
|
|
return m_IncompleteExpr;
|
2015-02-10 13:27:02 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
bool ScriptError::IsHandledByDebugger() const
|
2015-11-05 14:29:45 +01:00
|
|
|
{
|
|
|
|
return m_HandledByDebugger;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptError::SetHandledByDebugger(bool handled)
|
|
|
|
{
|
|
|
|
m_HandledByDebugger = handled;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
posix_error::~posix_error() throw()
|
2014-12-20 15:29:04 +01:00
|
|
|
{
|
|
|
|
free(m_Message);
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
const char *posix_error::what() const throw()
|
2014-12-20 15:29:04 +01:00
|
|
|
{
|
|
|
|
if (!m_Message) {
|
|
|
|
std::ostringstream msgbuf;
|
|
|
|
|
|
|
|
const char * const *func = boost::get_error_info<boost::errinfo_api_function>(*this);
|
|
|
|
|
|
|
|
if (func)
|
|
|
|
msgbuf << "Function call '" << *func << "'";
|
|
|
|
else
|
|
|
|
msgbuf << "Function call";
|
|
|
|
|
|
|
|
const std::string *fname = boost::get_error_info<boost::errinfo_file_name>(*this);
|
|
|
|
|
|
|
|
if (fname)
|
|
|
|
msgbuf << " for file '" << *fname << "'";
|
|
|
|
|
|
|
|
msgbuf << " failed";
|
|
|
|
|
|
|
|
const int *errnum = boost::get_error_info<boost::errinfo_errno>(*this);
|
|
|
|
|
|
|
|
if (errnum)
|
|
|
|
msgbuf << " with error code " << *errnum << ", '" << strerror(*errnum) << "'";
|
|
|
|
|
|
|
|
String str = msgbuf.str();
|
|
|
|
m_Message = strdup(str.CStr());
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_Message;
|
|
|
|
}
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
ValidationError::ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message)
|
2014-11-30 23:32:13 +01:00
|
|
|
: m_Object(object), m_AttributePath(attributePath), m_Message(message)
|
|
|
|
{
|
|
|
|
String path;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const String& attribute : attributePath) {
|
2014-11-30 23:32:13 +01:00
|
|
|
if (!path.IsEmpty())
|
|
|
|
path += " -> ";
|
|
|
|
|
|
|
|
path += "'" + attribute + "'";
|
|
|
|
}
|
|
|
|
|
|
|
|
Type::Ptr type = object->GetReflectionType();
|
|
|
|
m_What = "Validation failed for object '" + object->GetName() + "' of type '" + type->GetName() + "'";
|
|
|
|
|
|
|
|
if (!path.IsEmpty())
|
|
|
|
m_What += "; Attribute " + path;
|
|
|
|
|
|
|
|
m_What += ": " + message;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ValidationError::~ValidationError() throw()
|
2014-11-30 23:32:13 +01:00
|
|
|
{ }
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
const char *ValidationError::what() const throw()
|
2014-11-30 23:32:13 +01:00
|
|
|
{
|
|
|
|
return m_What.CStr();
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ConfigObject::Ptr ValidationError::GetObject() const
|
2014-11-30 23:32:13 +01:00
|
|
|
{
|
|
|
|
return m_Object;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::vector<String> ValidationError::GetAttributePath() const
|
2014-11-30 23:32:13 +01:00
|
|
|
{
|
|
|
|
return m_AttributePath;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String ValidationError::GetMessage() const
|
2014-11-30 23:32:13 +01:00
|
|
|
{
|
|
|
|
return m_Message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidationError::SetDebugHint(const Dictionary::Ptr& dhint)
|
|
|
|
{
|
|
|
|
m_DebugHint = dhint;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Dictionary::Ptr ValidationError::GetDebugHint() const
|
2014-11-30 23:32:13 +01:00
|
|
|
{
|
|
|
|
return m_DebugHint;
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:36:35 +01:00
|
|
|
std::string icinga::to_string(const StackTraceErrorInfo&)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
std::string icinga::to_string(const errinfo_win32_error& e)
|
|
|
|
{
|
|
|
|
return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n";
|
|
|
|
}
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
std::string icinga::to_string(const errinfo_getaddrinfo_error& e)
|
|
|
|
{
|
|
|
|
String msg;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
msg = gai_strerrorA(e.value());
|
|
|
|
#else /* _WIN32 */
|
|
|
|
msg = gai_strerror(e.value());
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
return "[errinfo_getaddrinfo_error] = " + String(msg) + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string icinga::to_string(const ContextTraceErrorInfo& e)
|
|
|
|
{
|
|
|
|
std::ostringstream msgbuf;
|
|
|
|
msgbuf << "[Context] = " << e.value();
|
|
|
|
return msgbuf.str();
|
|
|
|
}
|