Skip to content

Conversation

jistiak
Copy link

@jistiak jistiak commented Jun 24, 2025

flet_cli/commands/run.py crashed whenever the spawned process wrote non-UTF-8 bytes to stdout (e.g. OpenCV, C printf, binary progress bars).

What & Why:
Running flet run on long-lived apps that spawn helper processes (e.g. camera capture, FFmpeg, OpenCV) eventually blows up with

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x91 in position …

because print_output() assumes p.stdout.readline() always returns valid UTF-8. Native libraries often write raw bytes directly to FD 1, bypassing Python’s I/O wrappers, so invalid sequences slip through and crash the thread.

Fix
line = p.stdout.readline().decode("utf-8", errors="replace")

errors="replace" converts any bad byte to �, guaranteeing the read never raises.

Behaviour is unchanged for valid UTF-8; the only difference is that the CLI now lives instead of dying.

Summary by Sourcery

Bug Fixes:

  • Decode stdout lines with errors="replace" to avoid crashes on non-UTF-8 bytes

`flet_cli/commands/run.py` crashed whenever the spawned process wrote non-UTF-8 bytes to stdout (e.g. OpenCV, C printf, binary progress bars).
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@CLAassistant
Copy link

CLAassistant commented Jun 24, 2025

CLA assistant check
All committers have signed the CLA.

@FeodorFitsner
Copy link
Contributor

Is this PR superseded by #5397?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants