[BUGFIX] ViewHelper Exceptions are logged in Production 12/40212/6
authorHelmut Hummel <helmut.hummel@typo3.org>
Fri, 12 Jun 2015 15:20:17 +0000 (17:20 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 16 Jun 2015 15:20:54 +0000 (17:20 +0200)
In Production context all Exceptions from ViewHelpers
will be silently logged.
Additionally, the output is discarded from rendering.
In Development they will be re-thrown, so the
global exception handler will be triggered.

Resolves: #32528
Releases: master
Change-Id: I4af4d03ff6048fcc8999f4a48d5c2897dc43fc4e
Reviewed-on: http://review.typo3.org/40212
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Peter Niederlag <peter.niederlag@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/fluid/Classes/Core/ViewHelper/AbstractViewHelper.php

index 4331b37..dd1b5ef 100644 (file)
@@ -10,6 +10,9 @@ namespace TYPO3\CMS\Fluid\Core\ViewHelper;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use Psr\Log\LoggerInterface;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Log\LogManager;
 
 /**
  * The abstract base class for all view helpers.
@@ -234,7 +237,7 @@ abstract class AbstractViewHelper {
         * Call the render() method and handle errors.
         *
         * @return string the rendered ViewHelper
-        * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
+        * @throws Exception
         */
        protected function callRenderMethod() {
                $renderMethodParameters = array();
@@ -246,13 +249,24 @@ abstract class AbstractViewHelper {
 
                try {
                        return call_user_func_array(array($this, 'render'), $renderMethodParameters);
-               } catch (\TYPO3\CMS\Fluid\Core\ViewHelper\Exception $exception) {
-                       // @todo [BW] rethrow exception, log, ignore.. depending on the current context
-                       return $exception->getMessage();
+               } catch (Exception $exception) {
+                       if (GeneralUtility::getApplicationContext()->isProduction()) {
+                               $this->getLogger()->error('A Fluid ViewHelper Exception was captured: ' . $exception->getMessage() . ' (' . $exception->getCode() . ')', array('exception' => $exception));
+                               return '';
+                       } else {
+                               throw $exception;
+                       }
                }
        }
 
        /**
+        * @return LoggerInterface
+        */
+       protected function getLogger() {
+               return GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
+       }
+
+       /**
         * Initializes the view helper before invoking the render method.
         *
         * Override this method to solve tasks before the view helper content is rendered.