Repository navigation
fix: return null from configuration when the device is unconfigured - #125
Merged
thegecko merged 2 commits intoDec 3, 2026
Merged
Conversation
`UsbDevice.configuration` threw "configuration error: device is not configured" when the device had no active configuration (e.g. a vendor-specific class device on macOS right after it is plugged in, where the OS does not select a configuration). Per the WebUSB spec the attribute is nullable, so return null instead, letting callers check it and call selectConfiguration() as they would in a browser. Any ActiveConfigurationError from nusb now maps to null, which matches Chromium: it also reports null when the active configuration value has no matching descriptor. Errors from opening the device are still thrown. The generated TypeScript type is updated to `USBConfiguration | null`, matching @types/w3c-web-usb. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ychsn
marked this pull request as ready for review
December 3, 2026 11:43
Member
|
Thanks for opening this PR @ychsn ! All looks good to me |
thegecko
approved these changes
Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I found this on macOS while using an older USB device, a Sony RC-S380 NFC reader (
054c:06c1). The impact is limited: macOS leaves devices with a vendor-specific device class (bDeviceClass 0xFF) unconfigured after they are plugged in, and readingdevice.configurationin that state throws instead of returningnull.Changes
UsbDevice.configurationnow returnsnullinstead of throwingconfiguration error: device is not configuredwhen the device has no active configuration, as the WebUSB spec defines the attribute as nullable.ActiveConfigurationErrorfrom nusb maps tonull, since its configuration value is not public. This matches Chromium, which also returnsnullwhen no descriptor matches the active configuration value. Errors from opening the device are still thrown.configurationgetter returnednullin the same cases.USBConfiguration | null, matching@types/w3c-web-usb.Fixes
Checklist
Have you...
No automated test is added: there is no WebUSB call that puts a device back into the unconfigured state, and the existing hardware tests use a demo device that is already configured. I tested manually on macOS with a Sony RC-S380 (
054c:06c1,bDeviceClass 0xFF) right after plugging it in:configurationreturnsnull, thenselectConfiguration(1)andclaimInterface(0)succeed. On the configured device it still returns the configuration object.This change was written with the help of Claude Code (an AI coding assistant). I have reviewed the change and tested it on hardware as described above.