mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-04-11 12:36:01 +00:00
improve error reporting, remove duplicate code
This commit is contained in:
@@ -101,3 +101,30 @@ std::string Version::AsString() {
|
||||
ss << int(major) << "." << int(minor) << "." << int(patch);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string GetPlatformAgnosticErrorString() {
|
||||
#ifdef WIN32
|
||||
// This will provide us with the error code and an error message, all in one.
|
||||
int err;
|
||||
char msgbuf[256];
|
||||
msgbuf[0] = '\0';
|
||||
|
||||
err = GetLastError();
|
||||
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr,
|
||||
err,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msgbuf,
|
||||
sizeof(msgbuf),
|
||||
nullptr);
|
||||
|
||||
if (*msgbuf) {
|
||||
return std::to_string(GetLastError()) + " - " + std::string(msgbuf);
|
||||
} else {
|
||||
return std::to_string(GetLastError())
|
||||
}
|
||||
#else // posix
|
||||
return std::strerror(errno);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user