Skip to content

Catch uncaught exceptions in Console::run() and render a CLI error #51

Description

@HafizMMoaz

Console::run() calls $command->run() with no try/catch (src/Console.php:284-304), so any exception escaping a command reaches PHP's default handler. The user gets a raw fatal error and a stack trace on STDOUT, with display_errors deciding how much of it, and the exit code is 255 rather than something meaningful.

For a console library this is the one place where a friendly failure matters most, and everything needed is already here: CLI::error() for the STDERR path, and CLI::isQuiet() / an IS_DEV style flag to decide whether to show the trace.

Suggested behaviour:

  • Catch Throwable around the command dispatch.
  • Print message in red on STDERR, plus the class name and the trace when the console is in a debug mode.
  • Exit with a non zero code (1, or the exception code when it is in range).
  • Leave a hook so an application can register its own handler, since a framework will usually want to log it as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions