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 #19011

Merged
merged 1 commit into from
Dec 5, 2022

Conversation

maribu
Copy link
Member

@maribu maribu commented Dec 5, 2022

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.
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: tools Area: Supplementary tools labels Dec 5, 2022
@maribu maribu requested a review from chrysn December 5, 2022 10:11
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 5, 2022
@benpicco benpicco added the CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs label Dec 5, 2022
@riot-ci
Copy link

riot-ci commented Dec 5, 2022

Murdock results

✔️ PASSED

572a713 dist/tools/usb-serial: fix exception on missing entries

Success Failures Total Runtime
1 0 1 52s

Artifacts

@benpicco benpicco merged commit 3b23cb6 into RIOT-OS:master Dec 5, 2022
@maribu maribu deleted the dist/tools/usb-serial/ttys.py branch December 5, 2022 13:33
@maribu
Copy link
Member Author

maribu commented Dec 5, 2022

Thx :)

@maribu
Copy link
Member Author

maribu commented Dec 5, 2022

Backport provided in #19018

bors bot added a commit that referenced this pull request Dec 11, 2022
19012: boards/arduino-mega2560: add TTY_BOARD_FILTER r=gschorcht a=maribu

### Contribution description

This allows automatically selecting TTY actually belonging to an
Arduino Mega2560 if `MOST_RECENT_PORT=1` is set.

### Testing procedure

```
make BOARD=arduino-mega2560 MOST_RECENT_PORT=1 -C examples/default flash term
```

Should automatically select the TTY of the most recently connected Arduino Mega2560, even if a board of a different type is connect more recently.

### Issues/PRs references

- [x] depends on (and includes) #19011

Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Co-authored-by: Marian Buschsieweke <maribu@users.noreply.github.com>
bors bot added a commit that referenced this pull request Dec 11, 2022
19012: boards/arduino-mega2560: add TTY_BOARD_FILTER r=gschorcht a=maribu

### Contribution description

This allows automatically selecting TTY actually belonging to an
Arduino Mega2560 if `MOST_RECENT_PORT=1` is set.

### Testing procedure

```
make BOARD=arduino-mega2560 MOST_RECENT_PORT=1 -C examples/default flash term
```

Should automatically select the TTY of the most recently connected Arduino Mega2560, even if a board of a different type is connect more recently.

### Issues/PRs references

- [x] depends on (and includes) #19011

Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
@kaspar030 kaspar030 added this to the Release 2023.01 milestone Jan 19, 2023
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 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.

4 participants