Skip to content

UnicodeEncodeError crash on Windows (cp1252) from Rich spinner characters #91

@brettlhartt

Description

@brettlhartt

Description

smpmgr upgrade crashes with UnicodeEncodeError on Windows when the console codepage is cp1252 (the default for most Western Windows systems). The Rich library's braille spinner character \u2819 cannot be encoded in cp1252, causing the entire upgrade to abort even though the upload may have started.

Steps to Reproduce

  1. Windows 11 with default cp1252 console codepage
  2. Run:
    py -m smpmgr --port COM14 upgrade firmware.signed.bin
    
  3. smpmgr crashes during the progress spinner display

Expected Behavior

The upload should complete without crashing. The progress display should use characters compatible with the console encoding, or smpmgr should set PYTHONIOENCODING=utf-8 / handle encoding gracefully.

Actual Behavior

UnicodeEncodeError: 'charmap' codec can't encode character '\u2819' in position 0: character maps to <undefined>

Full traceback (trimmed):

  File "...\rich\_win32_console.py", line 441, in write_styled
    self.write_text(text)
  File "...\rich\_win32_console.py", line 402, in write_text
    self.write(text)
  File "...\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character '\u2819' in position 0: character maps to <undefined>

The crash originates in Rich's LegacyWindowsTerm when rendering the braille spinner (\u2819).

Workaround

Setting PYTHONIOENCODING=utf-8 before running smpmgr avoids the crash, though spinner characters render as mojibake:

set PYTHONIOENCODING=utf-8
py -m smpmgr --port COM14 upgrade firmware.signed.bin

Environment

  • OS: Windows 11 Pro 10.0.26200
  • Python: 3.12.7
  • smpmgr: 0.17.0
  • smpclient: 6.1.0
  • smp: 4.0.2
  • Console codepage: cp1252 (Western European, Windows default)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions