Improve error message for failed error formatting
This commit is contained in:
parent
dc282b6ab5
commit
3361dcf088
@ -1,10 +1,6 @@
|
|||||||
#include "log_tr.hpp"
|
#include "log_tr.hpp"
|
||||||
|
|
||||||
namespace detail {
|
detail::LogTr log_tr(const char* formatString)
|
||||||
|
|
||||||
LogTr log_tr(const char* formatString)
|
|
||||||
{
|
{
|
||||||
return detail::LogTr(formatString);
|
return detail::LogTr(formatString);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
@ -19,6 +19,8 @@ class LogTr {
|
|||||||
return m_utf8String.constData();
|
return m_utf8String.constData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator QString() const { return m_string; }
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
LogTr& arg(Args&&... args)
|
LogTr& arg(Args&&... args)
|
||||||
{
|
{
|
||||||
@ -31,8 +33,8 @@ class LogTr {
|
|||||||
QByteArray m_utf8String;
|
QByteArray m_utf8String;
|
||||||
};
|
};
|
||||||
|
|
||||||
LogTr log_tr(const char* formatString);
|
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
#define ltr(FormatString) "%s", (const char*)detail::log_tr(FormatString)
|
detail::LogTr log_tr(const char* formatString);
|
||||||
|
|
||||||
|
#define ltr(FormatString) "%s", (const char*)log_tr(FormatString)
|
||||||
|
@ -43,7 +43,7 @@ static QString getLastErrorString()
|
|||||||
const auto formatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
|
const auto formatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||||
|
|
||||||
if(FormatMessage(formatFlags, nullptr, lastErrorId, 0, reinterpret_cast<LPTSTR>(&msgBuf), 0, nullptr) == 0) {
|
if(FormatMessage(formatFlags, nullptr, lastErrorId, 0, reinterpret_cast<LPTSTR>(&msgBuf), 0, nullptr) == 0) {
|
||||||
return "FormatMessage failed";
|
return log_tr("FormatMessage failed with error code '%1' while formatting error message for code: %2").arg(GetLastError()).arg(lastErrorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto lastErrorString = fromTchar(msgBuf);
|
const auto lastErrorString = fromTchar(msgBuf);
|
||||||
|
Loading…
Reference in New Issue
Block a user