Fix USB discovery on Windows in case there is no USB port - #4996
Conversation
Fix openhab#4993 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
|
This is not tested. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in Windows USB serial device discovery where the application would crash when no USB ports are present. The fix wraps registry access calls in try-catch blocks to handle RuntimeExceptions gracefully.
- Added exception handling around all
Advapi32Util.registryGetKeys()andAdvapi32Util.registryGetValues()calls - Added debug logging for registry access failures
- Returns empty results or continues processing when registry operations fail
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
andrewfg
left a comment
There was a problem hiding this comment.
I never saw a Windows PC without a USB port, so would not know how to physically test it. However the code LGTM.
|
You can disable USB ports in the BIOS or in the device manager or not install the device drivers. Old PCs also don't have them. 😄 |
|
What is your feeling about Copilot suggestion ? |
I think any exception is bad. So you should catch and log them all. Trying to double guess what detail exceptions may or may not be thrown, on whatever machine and OS it may be, seems like an invitation for another user to open another issue at sometime. Just catch them all.. |
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
|
I finally applied Copilot suggestions after checking the code of Advapi32Util.registryGetKeys and Advapi32Util.registryGetValues. |
|
A backport to 5.0.x is probably recommended. |
Fix #4993 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Fix #4993