Skip to content

Colorize CLI error banner#15408

Merged
josevalim merged 2 commits into
elixir-lang:mainfrom
kevinschweikert:colorize-cli-error-banner
May 21, 2026
Merged

Colorize CLI error banner#15408
josevalim merged 2 commits into
elixir-lang:mainfrom
kevinschweikert:colorize-cli-error-banner

Conversation

@kevinschweikert
Copy link
Copy Markdown
Contributor

@kevinschweikert kevinschweikert commented May 21, 2026

I noticed that the error message from the cli output is not colored and thought it would improve readability, when more salient. Hope this improves the overall experience. It's gated behind the --color flag to not break existing output parsing.

Claude Opus was used to assist in this PR

Before:
image

After:
image

The script-crash path in Kernel.CLI.print_error/3 now renders the
exception banner (e.g. "** (ArgumentError) ...") in red when
IO.ANSI.enabled?/0 is true. The stacktrace stays plain.

Coloring is opt-in via a new ansi? argument on Kernel.CLI.format_error/4
that defaults to false, so callers that build Mix.Task.Compiler.Diagnostic
messages from the same helper keep producing plain text and do not leak
escape codes into existing consumers (see elixir-lang#13142).

Assisted-by: claude-code:claude-opus-4-7
@josevalim
Copy link
Copy Markdown
Member

This is good to me, we don't need a --color flag. I also think IO.ANSI.format already checks if ansi is enabled.

@kevinschweikert
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I've seperated the different components to color them in the print_error/3 function accordingly to not break the consumers of format_error/3. It now works without the --color flag:

image

@kevinschweikert kevinschweikert changed the title Colorize CLI error banner when ANSI is enabled Colorize CLI error banner May 21, 2026
@josevalim josevalim merged commit 97abb54 into elixir-lang:main May 21, 2026
14 of 15 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants