rust-embedded-community / usb-device

Experimental device-side USB framework for microcontrollers in Rust.
MIT License
414 stars 77 forks source link

Errors during get_configuration_descriptors get silently eaten #58

Closed lkolbly closed 4 months ago

lkolbly commented 3 years ago

https://github.com/mvirkkunen/usb-device/blob/258ad5b9e44b6ef9b0b7fa55254b12db0a53fc3f/src/device.rs#L413-L417

If get_configuration_descriptors throws an error (e.g. because of a buffer overflow), the error will exit the .accept() call and then get dropped by the .ok() (which will convert errors to None and drop the error). This makes it somewhat more difficult to debug when the configuration descriptors are too long (for example).

I'm not entirely sure what the correct behaviour should be. One option would be to unwrap() and panic (which is probably reasonable here, since it'll always panic essentially when the device boots, so it's easy to detect). The other option would be to make get_descriptor (and therefore control_in) return Result, which is probably the much more invasive solution (it'd be difficult to integrate with various class drivers).