【发布时间】:2019-08-20 21:32:58
【问题描述】:
我的代码中某处有 MappingException。请帮助我如何在引发异常的代码中找到位置?
[29-Mar-2019 22:30:26 Europe/Moscow] PHP Fatal error: Uncaught Doctrine\Common\Persistence\Mapping\MappingException: Class 'Client' does not exist in /var/www/virtual/account/htdocs/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:93
Stack trace:
#0 /var/www/virtual/account/htdocs/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php(24): Doctrine\Common\Persistence\Mapping\MappingException::nonExistingClass('Client')
#1 /var/www/virtual/account/htdocs/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(251): Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getParentClasses('Client')
#2 /var/www/virtual/account/htdocs/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(284): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getParentClasses('Client')
#3 /var/www/virtual/account/htdocs/vendor/doctrine/orm/lib/Doc in /var/www/virtual/account/htdocs/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php on line 93
如果我会做这样的事情会有所帮助还是我会得到与现在相同的堆栈跟踪?
try {
// application init
$app->init();
} catch (Doctrine\Common\Persistence\Mapping\MappingException $e) {
error_log("MappingException: " . $e->getTraceAsString());
throw $e;
}
更新
问题与 Doctrine 不完全相关,而是与堆栈跟踪的长度有关,该长度太大并且不适合 1024 字节(默认 php 的设置)。所以,只需要增加堆栈跟踪的最大长度,这可以通过以下命令来完成:
ini_set('log_errors_max_len', 0); // 0 - infinity length allow
【问题讨论】:
-
我没有使用过教义。但看起来像一个失败的依赖注入。您的任何类是否等待 Client 类的依赖项?
-
是的,看起来像依赖注入问题,我检查了我所有的实体、存储库和其他所有内容,但没有找到任何东西。我认为现代 ORM 工具应该提供详细的错误报告,其中包括代码中引发异常的位置。
标签: php debugging exception doctrine-orm doctrine