ARMmbed / ARMmbed/mbed-tools

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

Open
#333 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
49
Forks
32
PR merge metrics
No merged PRs in 30d

Description

**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

Contributor guide

Open the contributing guide

Research direction

Start in mbed_tools/devices/_internal/darwin/device_detector.py, especially _assemble_candidate_data and _format_vendor_id, then reproduce the failure with mbed-tools detect using a USB peripheral missing vendor_id. Check the related product_id and serial_num handling as well. Done means peripherals with missing required data are discarded instead of causing IndexError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.