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

dist/tools/usb-serial: fix exception on missing entries [backport 2022.10] #19018

Conversation

maribu
Copy link
Member

@maribu maribu commented Dec 5, 2022

Backport of #19011

Contribution description

For some TTY interfaces no DB entry exists, which is reflected by having a None in tty[key]. Trying to match a regex against None in turn resulted then in an exception.

This fixes the issue by treating a filter applied on a non-existing entry as not matching.

Testing procedure

With the following TTYs attached:

$ ./dist/tools/usb-serial/ttys.py
path driver vendor model model_db serial ctime iface_num
/dev/ttyACM1 cdc_acm Arduino (www.arduino.cc) 0042 Mega 2560 R3 (CDC ACM) 857353134333519002C1 10:43:21 0
/dev/ttyACM2 cdc_acm NXP Semiconductors LPC-LINK2 CMSIS-DAP V5.173 None NRA1AQCQ 10:43:31 1
/dev/ttyACM0 cdc_acm Valve Software Steam Deck Controller None MEDA20927049 10:28:36 3

In master

$ ./dist/tools/usb-serial/ttys.py --vendor 'Arduino' --model-db 'Mega 2560'
Traceback (most recent call last):
  File "/home/maribu/Repos/software/RIOT/examples/default/../../dist/tools/usb-serial/ttys.py", line 229, in <module>
    print_ttys(sys.argv)
  File "/home/maribu/Repos/software/RIOT/examples/default/../../dist/tools/usb-serial/ttys.py", line 212, in print_ttys
    if tty["serial"] not in args.exclude_serial and filters_match(filters, tty):
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/maribu/Repos/software/RIOT/examples/default/../../dist/tools/usb-serial/ttys.py", line 50, in filters_match
    if not regex.match(tty[key]):
           ^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

With this PR:

$ ./dist/tools/usb-serial/ttys.py --vendor 'Arduino' --model-db 'Mega 2560'
path driver vendor model model_db serial ctime iface_num
/dev/ttyACM1 cdc_acm Arduino (www.arduino.cc) 0042 Mega 2560 R3 (CDC ACM) 857353134333519002C1 10:43:21 0

Issues/PRs references

None

For some TTY interfaces no DB entry exists, which is reflected by
having a `None` in `tty[key]`. Trying to match a regex against `None`
in turn resulted then in an exception.

This fixes the issue by treating a filter applied on a non-existing
entry as not matching.

(cherry picked from commit 572a713)
@maribu maribu added Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Process: release backport Integration Process: The PR is a release backport of a change previously provided to master Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Dec 5, 2022
@maribu maribu requested a review from benpicco December 5, 2022 20:35
@riot-ci
Copy link

riot-ci commented Dec 5, 2022

Murdock results

✔️ PASSED

75b8bc4 dist/tools/usb-serial: fix exception on missing entries

Success Failures Total Runtime
1 0 1 55s

Artifacts

This only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now.

@benpicco benpicco added the Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer label Dec 6, 2022
@maribu maribu merged commit 1ec729f into RIOT-OS:2022.10-branch Dec 6, 2022
@maribu
Copy link
Member Author

maribu commented Dec 6, 2022

Thx :)

@maribu maribu deleted the backport/2022.10/dist/tools/usb-serial/ttys.py branch December 6, 2022 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Process: release backport Integration Process: The PR is a release backport of a change previously provided to master Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants