Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more specific exception types #449

Open
doronz88 opened this issue Aug 21, 2022 · 2 comments
Open

Add more specific exception types #449

doronz88 opened this issue Aug 21, 2022 · 2 comments

Comments

@doronz88
Copy link

PyUSB should raise more accurate errors, such as USBBrokenPipeError instead of USBError for everything so users can treat these exceptions better.
I can create this as a PR if you aggree

@jonasmalacofilho
Copy link
Member

jonasmalacofilho commented Aug 22, 2022

PyUSB could indeed benefit from higher level and more (immediately) informative errors, but that's needs to go beyond replacing

raise USBError(..., LIBUSB_ERROR_PIPE, EPIPE)

with

raise USBBrokenPipeError()

Most errors that a backend may return depend not only on a situation, but also on the backend, platform and kernel/system driver in use. Not to mention that there are at least 3 different libusb-0.1 implementations...

So a thorough review of common error scenarios, and the many ways in which they can manifest in our backends, would be necessary in order to provide additional higher level errors.

But, despite this caveat, improvements in this area would be very much appreciated.

@mcuee
Copy link
Member

mcuee commented Aug 23, 2022

Maybe we can fix libusb-1.0 backend first.

For libusb-0.1, indeed it may be more complicated.

  • libusb-compat-0.1
  • libusb-win32 for Windows
  • legacy libusb-0.1

@jonasmalacofilho jonasmalacofilho changed the title raising correct errors Add more specific exception types Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants