Skip to content

fix(cli): UnicodeEncodeError on Windows without PYTHONUTF8=1 #179

Description

@Wolfvin

Bug

On Windows, running any command that outputs Unicode characters (e.g. in trace output) without PYTHONUTF8=1 crashes with:

UnicodeEncodeError: 'charmap' codec can't encode character '→' in position 440: character maps to <undefined>

Root cause: Windows default stdout encoding is cp1252 (or similar), which cannot encode and other Unicode symbols used in path strings like sidepanel.ts → auth/google-auth-cache.ts.

Fix

In codelens.py (or the CLI entry point), force UTF-8 stdout/stderr at startup:

import sys, io
if sys.stdout.encoding != 'utf-8':
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
    sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')

This should be done unconditionally at the top of the entry point — do not rely on the user setting PYTHONUTF8=1. Users on Windows should not need an env var to get working output.

Definition of Done

  • All commands produce correct output on Windows without PYTHONUTF8=1
  • and other Unicode chars in trace paths render correctly or are replaced with ASCII fallback (->) without crashing
  • No change in behavior on Linux/macOS

Labels

type: bug-fix exec: parallel

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug-fixRegression or broken behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions