From d57a148b8b72cd10afae1aa0e3958cffaff4c137 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 17 Mar 2019 10:46:08 +0100 Subject: [PATCH] [DI] fix casting AutowiringFailedException to string when its callback throws --- .../DependencyInjection/Compiler/AutowirePass.php | 11 ++++++++++- .../DependencyInjection/Compiler/PassConfig.php | 7 ++++++- .../Exception/AutowiringFailedException.php | 6 +++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 5aa6680e7e..6a9c923768 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -226,7 +226,16 @@ class AutowirePass extends AbstractRecursivePass if ($parameter->isDefaultValueAvailable()) { $value = $parameter->getDefaultValue(); } elseif (!$parameter->allowsNull()) { - throw new AutowiringFailedException($this->currentId, $failureMessage); + if (\function_exists('xdebug_disable')) { + xdebug_disable(); + } + try { + throw new AutowiringFailedException($this->currentId, $failureMessage); + } finally { + if (\function_exists('xdebug_enable')) { + xdebug_enable(); + } + } } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index e39cd4981a..bd9c340eda 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -84,10 +84,15 @@ class PassConfig new RemoveUnusedDefinitionsPass(), new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()), new AnalyzeServiceReferencesPass(), - new DefinitionErrorExceptionPass(), new CheckExceptionOnInvalidReferenceBehaviorPass(), new ResolveHotPathPass(), ]]; + + $this->afterRemovingPasses = [ + 100 => [ + new DefinitionErrorExceptionPass(), + ], + ]; } /** diff --git a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php index 05f134a942..be2bd26dca 100644 --- a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php +++ b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php @@ -47,7 +47,11 @@ class AutowiringFailedException extends RuntimeException $messageCallback = $this->messageCallback; $this->messageCallback = null; - return $this->message = $messageCallback(); + try { + return $this->message = $messageCallback(); + } catch (\Throwable $e) { + return $this->message = $e->getMessage(); + } } }; }