Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 4e2f6e8

Browse files
committed
improve win error logging
1 parent 9505513 commit 4e2f6e8

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

src/plugins/keystores/wincred/wincredkeystore.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool WinCredKeyStore::contains(const QString &key) const
3737
if(error == ERROR_NOT_FOUND)
3838
return false;
3939
else
40-
throw QtDataSync::KeyStoreException(this, formatWinError(error));
40+
throw QtDataSync::KeyStoreException(this, qt_error_string(error));
4141
} else
4242
return true;
4343
}
@@ -56,14 +56,14 @@ void WinCredKeyStore::save(const QString &key, const QByteArray &pKey)
5656
cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
5757

5858
if(!CredWriteW(&cred, 0))
59-
throw QtDataSync::KeyStoreException(this, formatWinError(GetLastError()));
59+
throw QtDataSync::KeyStoreException(this, qt_error_string());
6060
}
6161

6262
QByteArray WinCredKeyStore::load(const QString &key)
6363
{
6464
auto res = tryLoad(key);
6565
if(res.isEmpty())
66-
throw QtDataSync::KeyStoreException(this, formatWinError(GetLastError()));
66+
throw QtDataSync::KeyStoreException(this, qt_error_string());
6767
else
6868
return res;
6969
}
@@ -72,7 +72,7 @@ void WinCredKeyStore::remove(const QString &key)
7272
{
7373
auto fullName = fullKey(key);
7474
if(!CredDeleteW(reinterpret_cast<LPWSTR>(const_cast<ushort*>(fullName.utf16())), CRED_TYPE_GENERIC, 0))
75-
throw QtDataSync::KeyStoreException(this, formatWinError(GetLastError()));
75+
throw QtDataSync::KeyStoreException(this, qt_error_string());
7676
}
7777

7878
QString WinCredKeyStore::fullKey(const QString &key)
@@ -82,24 +82,6 @@ QString WinCredKeyStore::fullKey(const QString &key)
8282
.arg(key);
8383
}
8484

85-
QString WinCredKeyStore::formatWinError(ulong error)
86-
{
87-
wchar_t *buffer = nullptr;
88-
auto num = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
89-
NULL,
90-
error,
91-
0,
92-
reinterpret_cast<LPWSTR>(&buffer),
93-
0,
94-
NULL);
95-
if(buffer) {
96-
auto res = QString::fromWCharArray(buffer, num);
97-
LocalFree(buffer);
98-
return res;
99-
} else
100-
return {};
101-
}
102-
10385
QByteArray WinCredKeyStore::tryLoad(const QString &key) const
10486
{
10587
PCREDENTIALW pCred = NULL;

src/plugins/keystores/wincred/wincredkeystore.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class WinCredKeyStore : public QtDataSync::KeyStore
2323
bool _open;
2424

2525
static QString fullKey(const QString &key);
26-
static QString formatWinError(ulong error);
2726
QByteArray tryLoad(const QString &key) const;
2827
};
2928

0 commit comments

Comments
 (0)