Skip to content

chore: prevent UnicodeEncodeError crashing error logging on Windows consoles#13482

Merged
Cristhianzl merged 1 commit into
release-1.10.0from
cz/fix-folder-tests-win
Jun 3, 2026
Merged

chore: prevent UnicodeEncodeError crashing error logging on Windows consoles#13482
Cristhianzl merged 1 commit into
release-1.10.0from
cz/fix-folder-tests-win

Conversation

@Cristhianzl

@Cristhianzl Cristhianzl commented Jun 3, 2026

Copy link
Copy Markdown
Member

On Windows CI, the e2e test validate-raise-errors-components.spec.ts fails
deterministically — it times out waiting for the error popup text
THIS IS A TEST ERROR MESSAGE to appear, even with the wait already bumped to
30s on release-1.10.0 (all 4 attempts failed).

Summary by CodeRabbit

  • Bug Fixes

    • Improved logging resilience for environments with limited character encoding support. The system now gracefully handles Unicode characters that cannot be encoded, replacing them with backslash representations instead of crashing.
  • Tests

    • Added comprehensive unit tests for stream resilience and exception logging in restricted encoding environments.

@Cristhianzl Cristhianzl changed the title fix: prevent UnicodeEncodeError crashing error logging on Windows consoles test: prevent UnicodeEncodeError crashing error logging on Windows consoles Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2546a6ff-34dd-41b0-9d9a-d6b1c33c0803

📥 Commits

Reviewing files that changed from the base of the PR and between cc97a32 and 75d7ab6.

📒 Files selected for processing (4)
  • src/lfx/src/lfx/log/__init__.py
  • src/lfx/src/lfx/log/_streams.py
  • src/lfx/tests/unit/log/__init__.py
  • src/lfx/tests/unit/log/test_streams.py

Walkthrough

This PR adds Unicode encoding resilience to stdout and stderr by reconfiguring them to use errors="backslashreplace" during module initialization. The implementation handles Windows cp1252 console encoding and other limited encodings to prevent UnicodeEncodeError when writing non-ASCII characters. Tests verify the reconfiguration works, exception logging succeeds, and the feature is safe when streams are unavailable.

Changes

Stream Resilience Feature

Layer / File(s) Summary
Core stream resilience implementation
src/lfx/src/lfx/log/_streams.py
Defines _reconfigure() helper to conditionally call reconfigure(errors="backslashreplace") on a stream if available, suppressing exceptions. The public make_streams_resilient() function applies reconfiguration to sys.stdout, sys.stderr, sys.__stdout__, and sys.__stderr__.
Module initialization hook
src/lfx/src/lfx/log/__init__.py
Imports make_streams_resilient from _streams and calls it at module load time, ensuring encoding resilience is active when the logging module is imported.
Test coverage for stream resilience
src/lfx/tests/unit/log/__init__.py, src/lfx/tests/unit/log/test_streams.py
Helper _cp1252_stream() creates test streams mimicking Windows cp1252 encoding. Tests verify make_streams_resilient() reconfigures both stdout/stderr to backslashreplace, exception logging via structlog does not crash on cp1252 streams, and the function safely handles None streams.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

test

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cz/fix-folder-tests-win

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 and usage tips.

@github-actions github-actions Bot added the bug Something isn't working label Jun 3, 2026
@Cristhianzl Cristhianzl changed the title test: prevent UnicodeEncodeError crashing error logging on Windows consoles chore: prevent UnicodeEncodeError crashing error logging on Windows consoles Jun 3, 2026
@Cristhianzl Cristhianzl merged commit 1d3a186 into release-1.10.0 Jun 3, 2026
106 of 108 checks passed
@Cristhianzl Cristhianzl deleted the cz/fix-folder-tests-win branch June 3, 2026 14:35
@github-actions github-actions Bot added test Changes to tests and removed bug Something isn't working labels Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

✅ Test Coverage Advisor

No source changes detected without accompanying tests. Thanks for keeping coverage up! 🎉

Advisory check only — never blocks merge.

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.32%. Comparing base (16f7331) to head (75d7ab6).
⚠️ Report is 5 commits behind head on release-1.10.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-1.10.0   #13482      +/-   ##
==================================================
- Coverage           57.76%   48.32%   -9.44%     
==================================================
  Files                2271     2129     -142     
  Lines              216876   204411   -12465     
  Branches            32450    14576   -17874     
==================================================
- Hits               125272    98779   -26493     
- Misses              90185   104212   +14027     
- Partials             1419     1420       +1     
Flag Coverage Δ
backend 64.83% <ø> (-0.01%) ⬇️
frontend 42.56% <ø> (-14.62%) ⬇️
lfx 52.87% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/lfx/src/lfx/log/_streams.py 100.00% <100.00%> (ø)

... and 1077 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 42%
42.56% (56406/132506) 69.25% (7639/11030) 41% (1263/3080)

Unit Test Results

Tests Skipped Failures Errors Time
4874 0 💤 0 ❌ 0 🔥 16m 6s ⏱️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant