Skip to content

CLI _echo doesn't work without import rich for non-String reports #1618

@mash-graz

Description

@mash-graz

For example this CLI command will throw an exception is rich isn't installed, although it works fine otherwise:

kasa --host 192.168.1.168 --username xxx --password xxx feature check_latest_firmware
Discovering device 192.168.1.168 for 10 seconds
Executing action check_latest_firmware
Raised error: expected string or bytes-like object, got 'UpdateInfo'
Run with --debug enabled to see stacktrace

the reason for this error reported by --debug:

[...]
Raised error: expected string or bytes-like object, got 'UpdateInfo'
Traceback (most recent call last):
[...]
File "/home/mash/.local/share/uv/tools/python-kasa/lib/python3.13/site-packages/kasa/cli/feature.py", line 125, in feature
    echo(response)
    ~~~~^^^^^^^^^^
  File "/home/mash/.local/share/uv/tools/python-kasa/lib/python3.13/site-packages/kasa/cli/common.py", line 57, in echo
    _echo(*args, **kwargs)
    ~~~~~^^^^^^^^^^^^^^^^^
  File "/home/mash/.local/share/uv/tools/python-kasa/lib/python3.13/site-packages/kasa/cli/common.py", line 45, in wrapper
    message = rich_formatting.sub("", message)
TypeError: expected string or bytes-like object, got 'UpdateInfo'

The regex substitution used in this replacement for richs print() function only works for strings.

More complex objects need to be preprocessed by repr() in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions