Skip to content

set_interface: Raise ValueError if no match is found #350

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

Merged
merged 1 commit into from
Jan 20, 2021

Conversation

tormodvolden
Copy link
Contributor

@tormodvolden tormodvolden commented Jan 13, 2021

Otherwise the type check for claim_interface will fail and the
error message is less helpful.

Signed-off-by: Tormod Volden [email protected]

BEFORE:

>>> dev.set_interface_altsetting(0, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyusb/usb/core.py", line 936, in set_interface_altsetting
    self._ctx.managed_set_interface(self, interface, alternate_setting)
  File "pyusb/usb/core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "pyusb/usb/core.py", line 210, in managed_set_interface
    self.managed_claim_interface(device, i)
  File "pyusb/usb/core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "pyusb/usb/core.py", line 178, in managed_claim_interface
    self.backend.claim_interface(self.handle, i)
  File "pyusb/usb/backend/libusb1.py", line 829, in claim_interface
    _check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

AFTER:

...
ValueError: No matching interface (0,1)

Otherwise the type check for claim_interface will fail and the
error message is less helpful.

Signed-off-by: Tormod Volden <[email protected]>
@jonasmalacofilho
Copy link
Member

Thanks!

@jonasmalacofilho jonasmalacofilho merged commit a54ebc7 into pyusb:master Jan 20, 2021
@tormodvolden tormodvolden deleted the intf_alt branch January 20, 2021 07:14
@mcuee mcuee added the core label Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants