Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP cuts off parts of long arguments in exception stack traces. How to tell it not to? [duplicate]

Below is an example of the error message from PHP 7 runtime:

PHP Fatal error: Uncaught Error: Class 'Predis\Connection\ConnectionException' not found in predis.php:4168

Stack trace:

#0 /var/www/api/libraries/predis/predis.php(4455): Predis\Connection\AbstractConnection->onConnectionError('Error while rea...')

Note ellipsis in the first stack trace line line marked #0:

('Error while rea...')

That's where the most important information would have been, had it not been cut off. Other error messages have the same problem, often cutting off very valuable parts of the message.

Is there a setting that we can use to print more information in stack traces? The exact version of PHP we're using is 7.1.1.

Update The exact issue we're having is described in How to disable PHP cutting off parts of long arguments in exception stack trace?. This question can be closed a dupe. The idea is to catch the exception, call Exception::getTrace() and construct the error message manually. The exception can be caught in the global hander, or in each try/catch block. The default implementation of Exception::getTraceAsString truncates long function arguments.

like image 520
Alex Avatar asked Apr 27 '17 18:04

Alex


1 Answers

If you wrap the calls that might fail in a try { ... } catch (Exception $e) { ... } block, you can display as much of the exception error messages as you wish.

You will also be able to control what you code does with the error, or helping to better avoid the issue in the future.

like image 92
Alister Bulman Avatar answered Oct 20 '22 00:10

Alister Bulman