Skip to content

fix(events): prevent UnicodeEncodeError crash on non-UTF-8 consoles#6522

Open
Aakash326 wants to merge 1 commit into
crewAIInc:mainfrom
Aakash326:fix/console-formatter-encoding
Open

fix(events): prevent UnicodeEncodeError crash on non-UTF-8 consoles#6522
Aakash326 wants to merge 1 commit into
crewAIInc:mainfrom
Aakash326:fix/console-formatter-encoding

Conversation

@Aakash326

Copy link
Copy Markdown

On Windows terminals using a legacy codepage (cp1252), printing emoji panel
titles (e.g. "🌊 Flow Started", "🔄 Flow Method Running") raises
UnicodeEncodeError inside ConsoleFormatter's sync event handlers. The event
bus swallows the exception and prints an error line instead, so every Flow
event silently fails to render and spams
"[CrewAIEventsBus] Sync handler error ..." for the whole run.

This is the same root cause behind several previously closed issues
(#3062, #2715, #2708, #823, #772, #755, #713, #665, #603) — each was patched
around a specific emoji/message rather than fixed at the source, so it keeps
recurring whenever a new emoji panel is added.

Fix: reconfigure the console's underlying stream to use errors="replace" on
init, so unencodable characters degrade to "?" instead of crashing.

Reproduced locally on Windows (cp1252 console) with a simple Flow —
confirmed crash before the fix, clean output after. Added regression test
covering both the stream reconfiguration and an emoji panel print against a
cp1252-encoded stream.

ConsoleFormatter builds a rich.Console around sys.stdout without
guarding its encoding. On Windows terminals using a legacy codepage
(cp1252), printing emoji panel titles (e.g. Flow Started, Flow
Method Running) raises UnicodeEncodeError inside the sync event
handlers. The event bus swallows the exception and prints an error
line instead, so every Flow event silently fails to render and spams
"[CrewAIEventsBus] Sync handler error ..." for the entire run.

This is the same root cause behind several previously closed issues
(crewAIInc#3062, crewAIInc#2715, crewAIInc#2708, crewAIInc#823, crewAIInc#772, crewAIInc#755, crewAIInc#713, crewAIInc#665, crewAIInc#603) - each was
patched around a specific emoji/message rather than fixed at the
source, so it keeps recurring as new emoji panels are added.

Reconfigure the underlying stream to use errors="replace" so
unencodable characters degrade to "?" instead of crashing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 81ca2cd6-02d0-41bf-9f12-4237642e7161

📥 Commits

Reviewing files that changed from the base of the PR and between fb8e93b and 70da14d.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/events/utils/console_formatter.py
  • lib/crewai/tests/utilities/test_console_formatter_encoding.py

📝 Walkthrough

Walkthrough

ConsoleFormatter now best-effort configures supported console streams with errors="replace". New tests verify this configuration and confirm emoji panel output does not raise on a cp1252 stream.

Changes

Console encoding handling

Layer / File(s) Summary
Stream error handling and regression coverage
lib/crewai/src/crewai/events/utils/console_formatter.py, lib/crewai/tests/utilities/test_console_formatter_encoding.py
ConsoleFormatter attempts to configure compatible streams with replacement error handling, and regression tests cover configuration plus emoji rendering on cp1252 output.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix for UnicodeEncodeError crashes on non-UTF-8 consoles.
Description check ✅ Passed The description is directly related to the code changes and regression coverage added in this pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant