How can I display Exception trace in laravel console command?

Dirk

I'm using Laravel 5.1 to create a console based application. During development I would like to display the exception trace when an error occurs. However, even if I use -v -vv or -vvv option in php artisan, I don't get an exception trace for my custom commands. I set APP_DEBUG=true in my .env, still no exception trace.

Output of php artisan some:unknowncommand is:

[InvalidArgumentException]                              
There are no commands defined in the "some" namespace.

Output of php artisan -v some:unknowncommand is:

[InvalidArgumentException]                              
  There are no commands defined in the "some" namespace.  

Exception trace:
 () at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:501
 Symfony\Component\Console\Application->findNamespace() at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:535
 Symfony\Component\Console\Application->find() at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:192
 Symfony\Component\Console\Application->doRun() at /Users/dirkpostma/Dropbox/Domains/dpepp/vendor/symfony/console/Application.php:126
...

Now, I created a very simple console command called dp:test, with following handle function:

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    generate error here
}

Output of php artisan dp:test is:

[Symfony\Component\Debug\Exception\FatalErrorException]
syntax error, unexpected 'error' (T_STRING)    

Output of php artisan -v dp:test is the same. Output of php artisan -vvv dp:test is the same.

The log file DOES show the exception trace, so somehow it should be possible to display it in cli. I don't even see the filename and linenumer where the error occurs... How can I take care of this?

Thanks in advance!

EDIT:

Is digged a bit further. In case I use this in my Command:

public function handle()
{
    throw new \Exception("test exception");
}

and I issue the command php artisan -v dp:test, the error trace IS printed. The trace is only not printed when the exception is thrown due to a PHP error. In Illuminate/Foundation/Bootstrap/HandleExceptions.php method bootstrap PHP errors are converted to Exceptions. When this occurs, an exception is thrown, but the -v is somehow ignored when printing. This is very inconvenient because it makes debugging CLI apps hard.

I think the solution can be found in vendor/symfony/console/Application.php, method renderException.

I'm going to dig further later, unless someone else can point the solution faster than me :-)

Dirk

I found reason why -v is ignored:

in Illuminate/Foundation/Bootstrap/HandleExceptions.php, the renderForConsole method instantiates a ConsoleOutput object, with default settings, not taking into account the verbosity settings the user asked for:

protected function renderForConsole($e)
{
    $this->getExceptionHandler()->renderForConsole(new ConsoleOutput, $e);
}

For this reason, whatever -v -vv or -vvv is set, the $output->getVerbosity() in vendor/symfony/console/Application.php is always lower than OutputInterface::VERBOSITY_VERBOSE, for that reason, the stack trace is not printed.

I probably start an issue on github for this, because I think it's much more convenient if errors are shown in CLI if user sets -v.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make apigility display exception trace in ApiProblem responses?

From Dev

How can I make apigility display exception trace in ApiProblem responses?

From Dev

How can I investigate an exception in console?

From Dev

How does the console obtain the stack trace of an exception?

From Dev

How can I disable the HTTP TRACE method in Laravel Forge?

From Dev

How can an Exception be created/thrown with no stack trace?

From Java

How can I get a JavaScript stack trace when I throw an exception?

From Dev

How can I display required message in laravel?

From Dev

No exception trace on Laravel

From Dev

How can I make a <select> in a popover display the selected option on console?

From Dev

How can I store output string to a variable AND display in console

From Dev

How can I make program print a stack trace automatically when an Exception occurs in Android

From Dev

In Python how can I raise a custom exception and do a trace back as well?

From Dev

How can I start a Rails console with command line arguments?

From Dev

How can I see the output console after running a nohup command?

From Dev

cURL for Windows: how can I send multiple line command in a console?

From Dev

how can I open a extra console and run a program in it with one command?

From Dev

how can I open a extra console and run a program in it with one command?

From Dev

how can I shutdown my system from the console with a command?

From Dev

How can I trace out modification of stored procedure with TSQL Command in SQL Server?

From Dev

How can I display all users and groups with a command?

From Dev

In bash, how can I display the output of a command ONLY if there is an error?

From Dev

How Can i display the output of MySQL “PRINT” Command in C#?

From Dev

How can I display the contents of a text file on the command line?

From Dev

How can I display all users and groups with a command?

From Dev

How can I configure the Command Prompt to display French correctly?

From Dev

How can I display the result of a command with two decimals in powershell?

From Java

How can I convert a stack trace to a string?

From Dev

How can I trace MY javascript?

Related Related

  1. 1

    How can I make apigility display exception trace in ApiProblem responses?

  2. 2

    How can I make apigility display exception trace in ApiProblem responses?

  3. 3

    How can I investigate an exception in console?

  4. 4

    How does the console obtain the stack trace of an exception?

  5. 5

    How can I disable the HTTP TRACE method in Laravel Forge?

  6. 6

    How can an Exception be created/thrown with no stack trace?

  7. 7

    How can I get a JavaScript stack trace when I throw an exception?

  8. 8

    How can I display required message in laravel?

  9. 9

    No exception trace on Laravel

  10. 10

    How can I make a <select> in a popover display the selected option on console?

  11. 11

    How can I store output string to a variable AND display in console

  12. 12

    How can I make program print a stack trace automatically when an Exception occurs in Android

  13. 13

    In Python how can I raise a custom exception and do a trace back as well?

  14. 14

    How can I start a Rails console with command line arguments?

  15. 15

    How can I see the output console after running a nohup command?

  16. 16

    cURL for Windows: how can I send multiple line command in a console?

  17. 17

    how can I open a extra console and run a program in it with one command?

  18. 18

    how can I open a extra console and run a program in it with one command?

  19. 19

    how can I shutdown my system from the console with a command?

  20. 20

    How can I trace out modification of stored procedure with TSQL Command in SQL Server?

  21. 21

    How can I display all users and groups with a command?

  22. 22

    In bash, how can I display the output of a command ONLY if there is an error?

  23. 23

    How Can i display the output of MySQL “PRINT” Command in C#?

  24. 24

    How can I display the contents of a text file on the command line?

  25. 25

    How can I display all users and groups with a command?

  26. 26

    How can I configure the Command Prompt to display French correctly?

  27. 27

    How can I display the result of a command with two decimals in powershell?

  28. 28

    How can I convert a stack trace to a string?

  29. 29

    How can I trace MY javascript?

HotTag

Archive