Search code examples
phpcodeignitersymfonydoctrine-ormdql

How to nicely display Doctrine2 Exceptions?


I have a query that output some very inconvenient error message:

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT p, e, c FROM Entity\Event e LEFT JOIN e.place p INNER JOIN e.categories c WITH c MEMBER OF :cat WHERE (e.dateStart BETWEEN :from AND :to) AND (p.latitude BETWEEN :minLat AND :maxLat) AND (p.latitude BETWEEN :minLat AND :maxLat) AND (p.latitude BETWEEN :minLat AND :maxLat) AND (p.longitude BETWEEN :minLng AND :maxLng) ORDER BY e.dateStart ASC' in /Users/YohannM/Sites/meetmyfriends-back/application/libraries/Doctrine/ORM/Query/QueryException.php:39Stack trace:#0 /Users/YohannM/Sites/meetmyfriends-back/application/libraries/Doctrine/ORM/Query/Parser.php(429): Doctrine\ORM\Query\QueryException::dqlError('SELECT p, e, c ...')#1 /Users/YohannM/Sites/meetmyfriends-back/application/libraries/Doctrine/ORM/Query/Parser.php(528): Doctrine\ORM\Query\Parser->semanticalError('':cat' is not d...', Array)#2 /Users/YohannM/Sites/meetmyfriends-back/application/libraries/Doctrine/ORM/Query/Parser.php(233): Doctrine\ORM\Query\Parser->_processDeferred in /Users/YohannM/Sites/meetmyfriends-back/application/libraries/Doctrine/ORM/Query/QueryException.php on line 49

As you can see, this is very inconvenient for debugging as my errors are truncated: Parser->semanticalError('':cat' is not d...',.

I have tried to vardump the excpetion but chrome crashes as the results returned is over 1GB !!

So my question is, how do I output the errors nicely. I'm not working with symfony2 but with Codeingniter

Thanks


Solution

  • You should not use vardump to dump an exception. Many Doctrine classes are interlinked, so, when you try to vardump an exception, it creates a recursion, and that is why your browser exhausts available memory and crashes.

    Doctrine has a utility that allows you to dump interlinked objects and specify the level of recursion. For example, to dump an object and all linked object up to 5 levels deep use this:

    \Doctrine\Common\Util\Debug::dump($object, 5);
    

    The default depth level is 2. More info - http://www.doctrine-project.org/api/common/2.4/class-Doctrine.Common.Util.Debug.html