Prevent UnicodeDecodeError when relaying child stdout – decode with errors="replace" #5396
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()
assumesp.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: