Skip to content

fix: use chalkStderr for stderr color detection#57

Merged
maff merged 2 commits into
mainfrom
fix/stderr-colorization
Mar 14, 2026
Merged

fix: use chalkStderr for stderr color detection#57
maff merged 2 commits into
mainfrom
fix/stderr-colorization

Conversation

@maff
Copy link
Copy Markdown
Owner

@maff maff commented Mar 14, 2026

Summary

  • Replace chalk (stdout-based TTY detection) with chalkStderr in all stderr output paths: logger, Commander error handler, and error formatting
  • Tie util.inspect color flag to chalkStderr.level so inspect output also respects stderr TTY state
  • Fixes colors breaking when stdout is redirected and ANSI escape codes leaking into files when stderr is redirected

Closes #51

Test plan

  • ./git-that-semver --log-level DEBUG > /dev/null — stderr should remain colored in terminal
  • ./git-that-semver --log-level DEBUG 2> /tmp/stderr.log && cat -v /tmp/stderr.log — no ^[[ escape codes in file
  • ./git-that-semver --config-file nonexistent.yaml 2> /tmp/err.log && cat -v /tmp/err.log — error output also clean
  • Normal terminal usage unchanged

All logging and error output goes to stderr, but was using chalk's
default instance which detects color support based on stdout TTY state.
This caused colors to break when only stdout was redirected, and ANSI
codes to leak into files when stderr was redirected.

Switch to chalkStderr which uses process.stderr.isTTY for detection,
and tie util.inspect's color flag to chalkStderr.level.

Closes #51
Copilot AI review requested due to automatic review settings March 14, 2026 21:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes stderr colorization behavior by switching all stderr-oriented output paths from stdout-based chalk detection to chalkStderr, ensuring ANSI styling follows process.stderr TTY state (and preventing escape-code leakage when stderr is redirected).

Changes:

  • Replace chalk with chalkStderr in the logger, platform resolution logging, and Commander’s stderr writer.
  • Tie util.inspect(..., colors) to chalkStderr.level so inspected objects only include color codes when stderr supports color.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/platform/index.ts Uses chalkStderr for the “Resolved platform” log message so platform logging respects stderr TTY.
src/logging/index.ts Routes all logger styling through chalkStderr and gates util.inspect colors based on chalkStderr.level.
index.ts Updates Commander stderr output and top-level error formatting to use chalkStderr.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Consumers now import `style` from the logging module instead of chalk
directly, keeping the stderr color detection in one place.
@maff maff merged commit 7684133 into main Mar 14, 2026
4 checks passed
@maff maff deleted the fix/stderr-colorization branch March 14, 2026 22:00
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.

Stderr colorization breaks when output is redirected

2 participants