mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
Windows: output useful error message for syscall errors
This commit is contained in:
parent
af63e300f3
commit
cc1e9c05ec
@ -180,6 +180,13 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, boo
|
|||||||
|
|
||||||
String message = ex.what();
|
String message = ex.what();
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
const auto *win32_err = dynamic_cast<const win32_error *>(&ex);
|
||||||
|
if (win32_err) {
|
||||||
|
message = to_string(*win32_err);
|
||||||
|
}
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
const auto *vex = dynamic_cast<const ValidationError *>(&ex);
|
const auto *vex = dynamic_cast<const ValidationError *>(&ex);
|
||||||
|
|
||||||
if (message.IsEmpty())
|
if (message.IsEmpty())
|
||||||
@ -424,6 +431,39 @@ std::string icinga::to_string(const StackTraceErrorInfo&)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
const char *win32_error::what() const noexcept
|
||||||
|
{
|
||||||
|
return "win32_error";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string icinga::to_string(const win32_error &e) {
|
||||||
|
std::ostringstream msgbuf;
|
||||||
|
|
||||||
|
const char * const *func = boost::get_error_info<boost::errinfo_api_function>(e);
|
||||||
|
|
||||||
|
if (func) {
|
||||||
|
msgbuf << "Function call '" << *func << "'";
|
||||||
|
} else {
|
||||||
|
msgbuf << "Function call";
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string *fname = boost::get_error_info<boost::errinfo_file_name>(e);
|
||||||
|
|
||||||
|
if (fname) {
|
||||||
|
msgbuf << " for file '" << *fname << "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
msgbuf << " failed";
|
||||||
|
|
||||||
|
const int *errnum = boost::get_error_info<errinfo_win32_error>(e);
|
||||||
|
|
||||||
|
if (errnum) {
|
||||||
|
msgbuf << " with error code " << Utility::FormatErrorNumber(*errnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
return msgbuf.str();
|
||||||
|
}
|
||||||
|
|
||||||
std::string icinga::to_string(const errinfo_win32_error& e)
|
std::string icinga::to_string(const errinfo_win32_error& e)
|
||||||
{
|
{
|
||||||
return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n";
|
return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n";
|
||||||
|
@ -127,7 +127,12 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
class win32_error : virtual public std::exception, virtual public boost::exception { };
|
class win32_error : virtual public std::exception, virtual public boost::exception {
|
||||||
|
public:
|
||||||
|
const char *what() const noexcept override;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string to_string(const win32_error& e);
|
||||||
|
|
||||||
struct errinfo_win32_error_;
|
struct errinfo_win32_error_;
|
||||||
typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user