getkirby / cli

Kirby Command Line Interface
MIT License
51 stars 5 forks source link

Return stack traces if throwable is catched, not just the message #37

Closed pwaldhauer closed 8 months ago

pwaldhauer commented 1 year ago

CLI.php, Line 98

public static function command(...$args): void
    {
        $cli = new static();

        try {
            $cli->run(...$args);
        } catch (Throwable $e) {
            $cli->error($e->getMessage());
        }
    }

In my opinion it would be helpful to have a way to have it return the stacktrace instead of only the message. Maybe if the debug mode is enabled or via an extra command line parameter?

lukasbestle commented 1 year ago

Given that it's a CLI, I think it would make sense to have the stack trace by default (after all the reader of CLI output is technical enough to use the CLI). But it would also be fine to hide the stack trace behind a -v|--verbose flag.

Since Throwable implements Stringable, the implementation would just require changing the line to:

$cli->error((string)$e);
kllmanu commented 12 months ago

Please add this, for instance, I've no clue where "Undefined array key 0" could come from in my code.