Skip to content

fix(scripts): force UTF-8 stdout in design_system.py on Windows (#112)#390

Merged
mrgoonie merged 1 commit into
nextlevelbuilder:mainfrom
ia-abatista:fix/design-system-windows-console
Jun 25, 2026
Merged

fix(scripts): force UTF-8 stdout in design_system.py on Windows (#112)#390
mrgoonie merged 1 commit into
nextlevelbuilder:mainfrom
ia-abatista:fix/design-system-windows-console

Conversation

@ia-abatista

Copy link
Copy Markdown
Contributor

What & why

On a non-UTF-8 Windows console (cp1252/gbk), running design_system.py as a CLI crashes with UnicodeEncodeError -- the same class of failure reported in #112 for search.py. The script prints box-drawing characters, check marks, and block swatches, but unlike search.py it never reconfigured stdout.

Note: the search.py instance from #112 is already fixed on main (it wraps stdout/stderr in a UTF-8 TextIOWrapper at lines 23-27). This PR covers the remaining design_system.py gap.

Change

Mirror search.py's wrapper in design_system.py:

if sys.stdout.encoding and sys.stdout.encoding.lower() != 'utf-8':
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
if sys.stderr.encoding and sys.stderr.encoding.lower() != 'utf-8':
    sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')

Applied to the source of truth (src/ui-ux-pro-max/scripts/) and the synced cli/assets/ copy. The check is idempotent, so it is a no-op when search.py imports design_system (stdout is already UTF-8 by then).

Verification

  • PYTHONIOENCODING=cp1252 python design_system.py "saas dashboard" --format ascii -> exit 0, no UnicodeEncodeError, still emits the box/swatch output (50 lines with non-ASCII).
  • npm run check:assets passes (both copies in sync).

Related to #112.

design_system.py prints box-drawing characters and swatches (--, OK marks,
block swatches), but unlike search.py it never reconfigured stdout. On a
non-UTF-8 Windows console (cp1252/gbk) running the CLI crashes with
UnicodeEncodeError, the same failure reported in nextlevelbuilder#112 for search.py.

Mirror the wrapper search.py already uses: re-wrap stdout/stderr in a
UTF-8 TextIOWrapper when the console encoding is not UTF-8. Applied to
the source of truth and the synced cli/assets copy.

Verified: the CLI runs clean under PYTHONIOENCODING=cp1252 (exit 0, no
UnicodeEncodeError) while still emitting the box/swatch output;
check:assets passes.

Related to nextlevelbuilder#112 (search.py is already fixed on main; this covers the
remaining design_system.py instance).
@ia-abatista

Copy link
Copy Markdown
Contributor Author

@mrgoonie more cleanup

@mrgoonie mrgoonie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maintainer review: approved. This is a narrow fix for the remaining Windows non-UTF-8 console path in design_system.py, mirrors the existing search.py stdout/stderr UTF-8 wrapper, and keeps source-of-truth plus packaged cli/assets copies in sync. Verified locally: npm run check:assets passes, and PYTHONIOENCODING=cp1252 python3 src/ui-ux-pro-max/scripts/design_system.py "saas dashboard" exits successfully while emitting the box/swatch output instead of raising UnicodeEncodeError. Duplicate/prior-work search only found this PR for the design_system.py-specific gap; related #112 search.py behavior is already fixed on main.

@mrgoonie mrgoonie merged commit d86f443 into nextlevelbuilder:main Jun 25, 2026
1 check passed
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.

2 participants