From c28266b031e925bfe6e57f3ba83a8f0f47211c81 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Mon, 3 Mar 2014 10:49:05 +0200 Subject: [PATCH] qtd3dservice: Improve error messaging Fix a number of bad error messages and make the formatting more consistent. Also correct the error ID structure that gets passed to the event log. Change-Id: Ia21b87b777e8b1bd456cb3ddde21054bb1051373 Reviewed-by: Oliver Wolff --- src/qtd3dservice/appxhandler.cpp | 11 ++++------- src/qtd3dservice/d3dservice.cpp | 10 +++++++--- src/qtd3dservice/registry.cpp | 2 +- src/qtd3dservice/xaphandler.cpp | 40 +++++++++++++++++++++++----------------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/qtd3dservice/appxhandler.cpp b/src/qtd3dservice/appxhandler.cpp index 2536d6b..281ffb8 100644 --- a/src/qtd3dservice/appxhandler.cpp +++ b/src/qtd3dservice/appxhandler.cpp @@ -94,7 +94,7 @@ extern int handleAppxDevice(int deviceIndex, const QString &app, const QString & HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Management_Deployment_PackageManager).Get(), &packageManager); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to instantiate package manager. HRESULT: 0x" << QByteArray::number(hr, 16).constData(); + qCWarning(lcD3DService) << "Unable to instantiate package manager:" << qt_error_string(hr); return 1; } @@ -102,8 +102,7 @@ extern int handleAppxDevice(int deviceIndex, const QString &app, const QString & ComPtr package; hr = packageManager->FindPackageByUserSecurityIdPackageFullName(NULL, packageFullName.Get(), &package); if (FAILED(hr)) { - qCWarning(lcD3DService).nospace() << "Unable to query package. HRESULT: 0x" - << QByteArray::number(hr, 16).constData(); + qCWarning(lcD3DService) << "Unable to query package:" << qt_error_string(hr); return 1; } if (!package) { @@ -113,15 +112,13 @@ extern int handleAppxDevice(int deviceIndex, const QString &app, const QString & ComPtr packageId; hr = package->get_Id(&packageId); if (FAILED(hr)) { - qCWarning(lcD3DService).nospace() << "Unable to get package ID. HRESULT: 0x" - << QByteArray::number(hr, 16).constData(); + qCWarning(lcD3DService) << "Unable to get package ID:" << qt_error_string(hr); return 1; } HSTRING packageFamilyName; hr = packageId->get_FamilyName(&packageFamilyName); if (FAILED(hr)) { - qCWarning(lcD3DService).nospace() << "Unable to get package name. HRESULT: 0x" - << QByteArray::number(hr, 16).constData(); + qCWarning(lcD3DService) << "Unable to get package name:" << qt_error_string(hr); return 1; } diff --git a/src/qtd3dservice/d3dservice.cpp b/src/qtd3dservice/d3dservice.cpp index a9ea15d..867c1dc 100644 --- a/src/qtd3dservice/d3dservice.cpp +++ b/src/qtd3dservice/d3dservice.cpp @@ -80,8 +80,8 @@ union ErrorId Customer = 0x20000000 }; struct { - ushort facility : 2; - ushort code : 2; + ushort facility; + ushort code; }; ulong val; }; @@ -167,19 +167,23 @@ void d3dserviceMessageHandler(QtMsgType type, const QMessageLogContext &, const if (eventSource) { if (type > QtDebugMsg) { ErrorId id = { ushort(FACILITY_NULL | ErrorId::Customer), type }; + WORD eventType; switch (type) { default: case 1: id.facility |= ErrorId::Informational; + eventType = EVENTLOG_SUCCESS; break; case 2: id.facility |= ErrorId::Warning; + eventType = EVENTLOG_WARNING_TYPE; break; case 3: id.facility |= ErrorId::Error; + eventType = EVENTLOG_ERROR_TYPE; break; } - ReportEvent(eventSource, type, 0, id.val, NULL, 2, 0, strings, NULL); + ReportEvent(eventSource, eventType, 0, id.val, NULL, 2, 0, strings, NULL); DeregisterEventSource(eventSource); } } diff --git a/src/qtd3dservice/registry.cpp b/src/qtd3dservice/registry.cpp index d6b5434..05b1893 100644 --- a/src/qtd3dservice/registry.cpp +++ b/src/qtd3dservice/registry.cpp @@ -47,7 +47,7 @@ static HKEY openBase() LONG result = RegCreateKeyEx(HKEY_CURRENT_USER_LOCAL_SETTINGS, L"qtd3dservice", 0, NULL, 0, KEY_ALL_ACCESS, NULL, ®Key, NULL); if (result != ERROR_SUCCESS) { - qCCritical(lcD3DService) << "Unable to open registry, error:" << result; + qCCritical(lcD3DService) << "Unable to open registry:" << qt_error_string(result); return 0; } return regKey; diff --git a/src/qtd3dservice/xaphandler.cpp b/src/qtd3dservice/xaphandler.cpp index 1f8bbc4..193bc12 100644 --- a/src/qtd3dservice/xaphandler.cpp +++ b/src/qtd3dservice/xaphandler.cpp @@ -87,7 +87,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l hr = coreConServer->handle()->GetConnection( device->handle(), 5000, NULL, connectionName.GetAddress(), &connection); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to initialize connection." + qCWarning(lcD3DService) << "Unable to initialize connection:" << coreConServer->formatError(hr); return 1; } @@ -95,7 +95,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l ComPtr connection3; hr = connection.As(&connection3); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to obtain connection3 interface." + qCWarning(lcD3DService) << "Unable to obtain connection3 interface:" << coreConServer->formatError(hr); return 1; } @@ -103,7 +103,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l ComPtr connection4; hr = connection.As(&connection4); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to obtain connection4 interface." + qCWarning(lcD3DService) << "Unable to obtain connection4 interface:" << coreConServer->formatError(hr); return 1; } @@ -119,7 +119,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l VARIANT_BOOL connected; hr = connection->IsConnected(&connected); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to query connection state." + qCWarning(lcD3DService) << "Unable to query connection state:" << coreConServer->formatError(hr); Sleep(1000); continue; @@ -130,7 +130,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l hr = connection->ConnectDevice(); connected = SUCCEEDED(hr); if (connected) { - qCDebug(lcD3DService) << "Connected."; + qCWarning(lcD3DService).nospace() << "Connected to " << device->name() << "."; wasDisconnected = true; } if (FAILED(hr)) { @@ -149,7 +149,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l while (!isInstalled) { hr = connection3->IsApplicationInstalled(bstr(app), &isInstalled); if (FAILED(hr)) { - qCCritical(lcD3DService) << "Unable to determine if package is installed - check that the app option contains a valid UUID." + qCCritical(lcD3DService) << "Unable to determine if package is installed:" << coreConServer->formatError(hr); return 1; } @@ -170,7 +170,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l hr = connection->GetFileInfo(bstr(remoteControlFile), &controlFileInfo); if (FAILED(hr)) { if (hr != 0x80070003 /* Not found */) { - qCWarning(lcD3DService) << "Unable to obtain file info" + qCWarning(lcD3DService) << "Unable to obtain file info:" << coreConServer->formatError(hr); Sleep(1000); continue; @@ -178,10 +178,16 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l // Not found, so let's upload it hr = connection->SendFile(bstr(localControlFile), bstr(remoteControlFile), 2, 2, NULL); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to send control file." - << coreConServer->formatError(hr); - wasDisconnected = true; - Sleep(1000); + if (hr == 0x8973190e) { + // This can happen during normal reinstallation, so continue + qCDebug(lcD3DService) << "Unable to send control file, retrying..."; + wasDisconnected = true; + Sleep(1000); + } else { + qCWarning(lcD3DService) << "Unable to send control file:" + << coreConServer->formatError(hr); + return 1; + } continue; } } @@ -190,7 +196,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l hr = connection->GetFileInfo(bstr(remoteSourcePath), &remoteDirectoryInfo); if (FAILED(hr)) { if (hr != 0x80070002 && hr != 0x80070003 /* Not found */) { - qCWarning(lcD3DService) << "Unable to get remote directory info." + qCWarning(lcD3DService) << "Unable to get remote directory info:" << coreConServer->formatError(hr); Sleep(1000); continue; @@ -199,7 +205,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l // Not found, create remote source path hr = connection->MakeDirectory(bstr(remoteSourcePath)); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to create the shader source directory." + qCWarning(lcD3DService) << "Unable to create the shader source directory:" << coreConServer->formatError(hr); continue; } @@ -208,7 +214,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l hr = connection->GetFileInfo(bstr(remoteBinaryPath), &remoteDirectoryInfo); if (FAILED(hr)) { if (hr != 0x80070002 && hr != 0x80070003 /* Not found */) { - qCWarning(lcD3DService) << "Unable to get remote directory info." + qCWarning(lcD3DService) << "Unable to get remote directory info:" << coreConServer->formatError(hr); Sleep(1000); continue; @@ -217,7 +223,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l // Not found, create remote source path hr = connection->MakeDirectory(bstr(remoteBinaryPath)); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to create the shader source directory." + qCWarning(lcD3DService) << "Unable to create the shader source directory:" << coreConServer->formatError(hr); continue; } @@ -232,7 +238,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l hr = connection->SetFileInfo(bstr(remoteControlFile), &controlFileInfo); round = 1; if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to update control file" + qCWarning(lcD3DService) << "Unable to update control file:" << coreConServer->formatError(hr); Sleep(1000); continue; @@ -243,7 +249,7 @@ extern int handleXapDevice(int deviceIndex, const QString &app, const QString &l SAFEARRAY *listing; hr = connection4->GetDirectoryListing(bstr(remoteSourcePath), &listing); if (FAILED(hr)) { - qCWarning(lcD3DService) << "Unable to get the shader source directory listing" + qCWarning(lcD3DService) << "Unable to get the shader source directory listing:" << coreConServer->formatError(hr); wasDisconnected = true; Sleep(1000); -- 2.7.4