Enhance error handling in WMI connection (#7833)
Added error handling for ConnectToServer calls to improve debugging.
Pablo Navarro committed
May 27, 2026 at 12:45 UTC
a5f3f192bf75d306e48d0d6bd3e0bf71b6e587fe
1 file changed
+14
-2
agents/modules_meshcore/win-wmi-fixed.js
+14
-2
@@ -382,7 +382,13 @@ function queryAsync(resourceString, queryString, fields)
382
handlers.locator.funcs = require('win-com').marshalFunctions(handlers.locator, LocatorFunctions);
383
384
handlers.services = require('_GenericMarshal').CreatePointer();
385
- if (handlers.locator.funcs.ConnectToServer(handlers.locator, resource, 0, 0, 0, 0, 0, 0, handlers.services).Val != 0) { throw ('Error calling ConnectToService'); }
385
+
386
+ // For easier debugging in case a certain WMI component is not available
387
+ var hr = handlers.locator.funcs.ConnectToServer(handlers.locator, resource, 0, 0, 0, 0, 0, 0, handlers.services).Val;
388
+ if (hr != 0) {
389
+ var hex = (hr < 0 ? hr + 0x100000000 : hr).toString(16).toUpperCase();
390
+ throw ('queryAsync: Error calling ConnectToServer: HRESULT=0x' + hex + ' resource=' + resourceString);
391
+ }
392
393
handlers.services.funcs = require('win-com').marshalFunctions(handlers.services.Deref(), ServiceFunctions);
394
handlers.p = p;
@@ -408,7 +414,13 @@ function query(resourceString, queryString, fields)
414
var locator = require('win-com').createInstance(require('win-com').CLSIDFromString(CLSID_WbemAdministrativeLocator), require('win-com').IID_IUnknown);
415
locator.funcs = require('win-com').marshalFunctions(locator, LocatorFunctions);
416
var services = require('_GenericMarshal').CreatePointer();
411
- if (locator.funcs.ConnectToServer(locator, resource, 0, 0, 0, 0, 0, 0, services).Val != 0) { throw ('Error calling ConnectToService'); }
417
+
418
+ // For easier debugging in case a certain WMI component is not available
419
+ var hr = locator.funcs.ConnectToServer(locator, resource, 0, 0, 0, 0, 0, 0, services).Val;
420
+ if (hr != 0) {
421
+ var hex = (hr < 0 ? hr + 0x100000000 : hr).toString(16).toUpperCase();
422
+ throw ('query: Error calling ConnectToServer: HRESULT=0x' + hex + ' resource=' + resourceString);
423
+ }
424
425
// Execute the Query
426
services.funcs = require('win-com').marshalFunctions(services.Deref(), ServiceFunctions);