Skip to content

Instantly share code, notes, and snippets.

@oliverthiele
Created July 22, 2014 20:33
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save oliverthiele/f1550a246dd8726ef136 to your computer and use it in GitHub Desktop.
Save oliverthiele/f1550a246dd8726ef136 to your computer and use it in GitHub Desktop.
Debugging errors like "An error occurred while trying to call Vendor\ExtKey\Controller\ModelController->showAction() " in extbase extensions
/**
* A special action which is called if the originally intended action could
* not be called, for example if the arguments were not valid.
*
* The default implementation sets a flash message, request errors and forwards back
* to the originating action. This is suitable for most actions dealing with form input.
*
* We clear the page cache by default on an error as well, as we need to make sure the
* data is re-evaluated when the user changes something.
*
* @return string
*/
protected function errorAction() {
echo 'ErrorAction';
$this->clearCacheOnError();
if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
echo 'Rewritten Property Mapper';
echo '<pre>';
foreach ($this->arguments->getValidationResults()->getFlattenedErrors() as $propertyPath => $errors) {
foreach ($errors as $error) {
$message .= 'Error for ' . $propertyPath . ': ' . $error->render() .
PHP_EOL;
}
echo 'Error: ' . $message;
}
echo '</pre>';
$errorFlashMessage = $this->getErrorFlashMessage();
if ($errorFlashMessage !== FALSE) {
$errorFlashMessageObject = new \TYPO3\CMS\Core\Messaging\FlashMessage(
$errorFlashMessage,
'',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
$this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject);
}
$referringRequest = $this->request->getReferringRequest();
if ($referringRequest !== NULL) {
$originalRequest = clone $this->request;
$this->request->setOriginalRequest($originalRequest);
$this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
$this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $referringRequest->getControllerExtensionName(), $referringRequest->getArguments());
}
$message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL;
return $message;
} else {
// @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
$this->request->setErrors($this->argumentsMappingResults->getErrors());
$errorFlashMessage = $this->getErrorFlashMessage();
if ($errorFlashMessage !== FALSE) {
$errorFlashMessageObject = new \TYPO3\CMS\Core\Messaging\FlashMessage(
$errorFlashMessage,
'',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
$this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject);
}
$referrer = $this->request->getInternalArgument('__referrer');
if ($referrer !== NULL) {
$this->forward($referrer['actionName'], $referrer['controllerName'], $referrer['extensionName'], $this->request->getArguments());
}
$message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL;
return $message;
}
}
@edrush
Copy link

edrush commented Aug 5, 2015

Good to know, helped us a lot! Thanks!

@metaxos
Copy link

metaxos commented Dec 4, 2015

Hi. Is there a way to trigger this (to test it)?

@metaxos
Copy link

metaxos commented Dec 5, 2015

Got the error now... BUT! If I clean my cache from Backend (the 3) then everything works as expected... how can this be a validation problem? ANy Idea?

@mkrappitz
Copy link

Thank you so much! Saved my day!

@Schweriner
Copy link

Very helpful. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment