Ref T321 Add extended error reporting in CAtomicFile::replaceOriginal

to try to gather more info on the problem saving the data cache session file.
This commit is contained in:
Mat Sutcliffe
2018-09-14 16:53:08 +01:00
committed by Klaus Basan
parent c3cf39e102
commit 74f3301679
3 changed files with 35 additions and 6 deletions

View File

@@ -9,6 +9,7 @@
#include "blackmisc/atomicfile.h"
#include "blackmisc/algorithm.h"
#include "blackmisc/logmessage.h"
#include <QDir>
#include <QFileInfo>
@@ -148,8 +149,22 @@ namespace BlackMisc
m_renameError = true;
wchar_t *s = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), 0, reinterpret_cast<LPWSTR>(&s), 0, nullptr);
setErrorString((replace ? "ReplaceFile: " : "MoveFileEx: ") + QString::fromWCharArray(s).simplified());
// MS 2018-09 Testing T321 ("failed to write session file")
//setErrorString((replace ? "ReplaceFile: " : "MoveFileEx: ") + QString::fromWCharArray(s).simplified());
CLogMessage(this).error((replace ? "ReplaceFile: " : "MoveFileEx: ") + QString::fromWCharArray(s).simplified() + "\n" + getStackTraceAlways().join("\n"));
LocalFree(reinterpret_cast<HLOCAL>(s));
// fall back to non-atomic remove-and-rename
if (exists(m_originalFilename))
{
QFile old(m_originalFilename);
if (!old.remove())
{
setErrorString(old.errorString());
return;
}
}
rename(m_originalFilename);
}
}
#else

View File

@@ -38,13 +38,20 @@
namespace BlackMisc
{
#if defined(QT_NO_DEBUG)
#if defined(QT_DEBUG)
QStringList getStackTrace()
{
return getStackTraceAlways();
}
#else
QStringList getStackTrace()
{
return { "No stack trace with release build" };
}
#elif defined(Q_OS_WIN32)
QStringList getStackTrace()
#endif
#if defined(Q_OS_WIN32)
QStringList getStackTraceAlways()
{
static QMutex mutex;
QMutexLocker lock(&mutex);
@@ -84,7 +91,7 @@ namespace BlackMisc
return result;
}
#elif defined(Q_CC_GNU)
QStringList getStackTrace()
QStringList getStackTraceAlways()
{
std::array<void*, 100> stack;
auto frames = backtrace(stack.data(), stack.size());
@@ -128,7 +135,7 @@ namespace BlackMisc
}
#else
// cppcheck-suppress unusedFunction
QStringList getStackTrace()
QStringList getStackTraceAlways()
{
return { "No stack trace on this platform" };
}

View File

@@ -19,8 +19,15 @@ namespace BlackMisc
{
/*!
* Returns a stack trace of the current thread of execution as a list of function names.
*
* Returns a dummy list in release build.
*/
BLACKMISC_EXPORT QStringList getStackTrace();
/*!
* Returns a stack trace of the current thread of execution as a list of function names.
*/
BLACKMISC_EXPORT QStringList getStackTraceAlways();
}
#endif