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

Running mbed-tools detect on mac_os fails when a USB peripheral does not provide some data #333

Open
tommaso-zandrini opened this issue May 29, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@tommaso-zandrini
Copy link

Describe the bug
Running mbed-tools detect on mac_os fails when a USB peripheral (i.e. my USB mouse) does not provide some data (in my case, there is no vendor_id in the USB device properties)

To Reproduce
Steps to reproduce the behavior:

  1. plug a USB device providing no vendor_id (for example, verify which info are provided by USB peripherals by running system_profiler SPUSBDataType)
  2. run mbed-tools detect
  3. the script crashes reporting IndexError: list index out of range

Expected behavior
mbed-tools detect should discard the USB peripheral with missing info, if they are necessary to detect the board, instead of throwing an error

Desktop (please complete the following information):

  • OS: mac_os
  • Version: 12.6.5

Mbed (please complete the following information):

  • Device: no device (issue independent from the connected device)
  • Mbed OS Version: 6.17.0
  • Mbed CLI 2 Version: 7.59.0

Additional context

in file mbed_tools/devices/_internal/darwin/device_detector.py
in function _assemble_candidate_data
the line device_data.get("vendor_id", "") produces a crash when the vendor_id is not provided by the peripheral

(I expect the same possible issue with the next two lines, using the same method to get "product_id" and "serial_num")

Traceback (most recent call last):
File "/myProject/bin/mbed-tools", line 8, in
sys.exit(cli())
File "/myProject/lib/python3.10/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/myProject/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/myProject/lib/python3.10/site-packages/mbed_tools/cli/main.py", line 38, in invoke
super().invoke(context)
File "/myProject/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/myProject/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/myProject/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/myProject/lib/python3.10/site-packages/mbed_tools/cli/list_connected_devices.py", line 29, in list_connected_devices
connected_devices = get_connected_devices()
File "/myProject/lib/python3.10/site-packages/mbed_tools/devices/devices.py", line 24, in get_connected_devices
for candidate_device in detect_candidate_devices():
File "/myProject/lib/python3.10/site-packages/mbed_tools/devices/_internal/detect_candidate_devices.py", line 17, in detect_candidate_devices
return detector.find_candidates()
File "/myProject/lib/python3.10/site-packages/mbed_tools/devices/_internal/darwin/device_detector.py", line 45, in find_candidates
candidate = _build_candidate(device_data)
File "/myProject/lib/python3.10/site-packages/mbed_tools/devices/_internal/darwin/device_detector.py", line 55, in _build_candidate
assembled_data = _assemble_candidate_data(device_data)
File "/myProject/lib/python3.10/site-packages/mbed_tools/devices/_internal/darwin/device_detector.py", line 65, in _assemble_candidate_data
"vendor_id": _format_vendor_id(device_data.get("vendor_id", "")),
File "/myProject/lib/python3.10/site-packages/mbed_tools/devices/_internal/darwin/device_detector.py", line 79, in _format_vendor_id
return vendor_id.split(maxsplit=1)[0]
IndexError: list index out of range

@tommaso-zandrini tommaso-zandrini added the bug Something isn't working label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant