Skip to content

CLI::style() skips color validation when ANSI is unsupported #44

Description

@HafizMMoaz

CLI::style() returns early when supportsAnsi() is false (src/CLI.php:206-208), before the ForegroundColor::from() / BackgroundColor::from() / Format::from() calls that validate the arguments. The documented @throws ValueError therefore depends on the terminal:

CLI::style('foo', 'not-a-color');
// ANSI terminal:      ValueError
// piped / --no-ansi:  returns 'foo', no error

That is the worst shape for this kind of check: a typo in a color name passes in CI or when output is redirected and only blows up on a developer machine, or the other way round. It is also why testStyleWithInvalidColor and its two siblings fail when the test process has no ANSI capable STDOUT (see the test portability issue).

Expected: validate and resolve the enums first, then decide whether to emit the codes. Same for write(), which forwards to style().

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions