I'm trying to set up custom error handling, so I setup an ErrorController.php file within the default module, under the controllers directory. However, when I try to go to access an invalid controller, an error is shown that an uncaught exception occurred. This bypasses the ErrorController file though, and when I print the contents of the response object, it does not show any exceptions. Does anyone know what I might be doing wrong here? Cheers!
Ok I fixed the issue, apparently all I needed to do was add the following code: $front->throwExceptions(false);
Related
I'm running drupal 8, composer and npm to perform gulp tasks.
When I run npm start.. my task manager: I get the following stack trace:
Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "render" filter.' in /web/project/web/themes/emulsify/components/_patterns/04-templates/basic-page/_basic_page.twig:26
Stack trace:
#0 /web/project/web/themes/emulsify/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(481): Twig_ExpressionParser->getFilterNodeClass('render', 26)
#1 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(466): Twig_ExpressionParser->parseFilterExpressionRaw(Object(Twig_Node_Expression_Name))
#2 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(320): Twig_ExpressionParser->parseFilterExpression(Object(Twig_Node_Expression_Name))
#3 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(212): Twig_ExpressionParser->parsePostfixExpression(Object(Twig_Node_Expression_Name))
#4 /web/project in /web/project/web/themes/project_theme/components/_patterns/04-templates/basic-page/_basic_page.twig on line 26
I've looked at installing twig-bridge / symfony twig via composer but I can't seem to get rid of the error message.
Do I just ditch using the twig filter "render"?
Update: 14/08/17
I've also ran into the same problem when trying to use the drupal_block function provided via Drupal 8's twig_tweak module.
The problem in the code above is that your Twig extension class is extending the internal Drupal Twig extension class. That breaks the Twig extensions added by Drupal core and that's why you are getting the error.
To fix this, you should make your Twig extensions extend Twigs internal Twig extension class. Your class should be defined like this:
class MyExtension extends \Twig_Extension {
After making that change, you can also remove arguments set for that class from the MODULE.services.yml
link
I've not seen this in the Drupal context, but working with other platforms that use Twig, I have seen similar issues occurring when an error occurs early in the platform setup process.
The typical sequence of events is like this:
The platform starts running its bootup; loading the CMS core, etc.
At some point early in this process, it hits an error.
It then tries to render an error page.
However, the error page uses a Twig template.
The startup process has not yet loaded all the twig extensions used in the template.
Boom, you get a twig error stating "unknown Twig function" instead of the real error message.
When I've had this before, it has proved very hard to diagnose what the actual error is.
The "correct" solution has been to modify the error page templates so that they are minimal and don't use any non-core twig functions. But if you're getting a crash early in the page load process it can be hard to actually do that.
In the first case, I resolved it by debugging the system and trapping what data was passed to the template. This showed me what the real error was. Resolving that error then stopped the twig error from occurring and allowed me to get into the system.
I don't know for sure if what you're seeing is the same kind of thing as what I was seeing, but it sounds similar so I hope this will help.
I'm building an application with ZF2.
I use ajax to POST some data on the application and when I trhrow a new Exception with this line:
throw new \Exception("Not Loged In.", 401);
The problem is everytime I throw a new error it returns a 500 even if I put anything as a second parameter of the exception.
Can anyone help me?
Thanks!
From zend framework's request lifecycle perspective every uncaught exception is an application error. You need a mechanism to convert that exceptions to meaningful HTTP responses before the framework convert them to an HTTP 50X for you.
For example, in your controller you can try something like below:
try {
$this->myService->tryToDoSomethingThatNeedsAuthentication();
} catch(AuthRequiredException $e) {
$this->getResponse()->setStatusCode($e->getCode()) // Assuming its 401
->setReasonPhrase($e->getMessage());
return;
} catch(\Exception) {
// handle other exceptions here
}
Problem is in your php configuration. Default Apache (or other server) hide details of your internal errors, so is returned short info:
Error 500 - internal server error
You must enable error_reporting:
in PHP:
http://php.net/manual/pl/function.error-reporting.php
or in php.ini in Apache configuration, and in .htaccess file it's possible. For developer's work you should show all errors.
I am creating two custom content type with reference to these pages:
https://www.drupal.org/node/2629550
https://www.drupal.org/node/2693979
Uncaught PHP Exception
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
"You have requested a non-existent service
"router.route_provider.old". Did you mean one of these:
"router.route_provider", "router.route_preloader"?" at
...\core\lib\Drupal\Component\DependencyInjection\Container.php
line 157
Could anyone please help me, why this is happening and how to fix it ?
I am using Drupal 8.1.8 version.
I checked in core.services.yml file, there is no route declared as "router.route_provider.old"
I have created a router names as "router.route_provider.old" by copying "router.route_provider" in the core.services.yml file, which solves my problem.
i think Drupal uses "router.route_provider.old" router as a temporary to copy "router.route_provider" router info. But as this router name is not exists, its throwing exception.
I don't know if this is a bug or there is better way to fix it.
Update:
A patch is provided here: https://www.drupal.org/node/2788087
I was trying to extend tx_news with some extra fields and was getting an error so I installed this extension to see if that worked: https://github.com/cyberhouse/t3ext-newsauthor
I get the same error on the news pages with my extension and the reference extension:
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be
resolved for action "error" in class
"Tx_Fluidpages_Controller_PageController".
and the following errors in the be log:
Core: Error handler (FE): PHP Warning: file_get_contents(): Filename
cannot be empty in
/var/www/ukcg6/typo3_src-6.1.7/typo3/sysext/fluid/Classes/View/TemplateView.php
line 187
I am using Typo3 6.1 with:
Fluidpages 2.1.0
Fluidcontent 3.1.0
Flux 6.0.3
VHS 1.8.5
I don't have time to setup your stack here now, but I'll try to help with some general advice on how to trace and locate such kinds of errors.
Basically you will need to trace the error back from the TemplateView.php line 187.
Starting there you look for the variable which is the filename. You can var_dump() that variable and it will probably be "null".
Then you follow that variable back to its origin in backwards order. That means each time this variable gets passed you search for the place in the source code where the function which gets it as a parameter is called.
Doing this you'll definitely find the point where something goes wrong. The filename variable is not properly set and that means one of the previously called functions which should set it screwed up.
I have just installed YII without any problems, but I cannot get into GII. I have uncommented the specific lines in mywebapp/protected/config/main.php to enable GII.
When I try to go to: localhost/myapp/index.php?r=gii I am redirected to localhost/myapp/index.php?r=gii/default/login.
I don't have the URL manager enabled it is a fresh installation on Wamp.
The error I get is this:
Fatal error: Cannot redeclare class CLogRouter in C:\wamp\www\yii\framework\logging\CLogRouter.php on line 53
The yii folder is the installation folder (did not know that the app is still using it).
What could be causing the trouble and how to get GII working? Thanks for your replies!
It is not clear what your problem is.
Getting redirected to /gii/default/login is good. This is where you log in with a password.
Your error "Cannot redeclare class CLogRouter" indicates that you are declaring CLogRouter twice. This probably happens in your protected/config/main.php.
However, I am under the impression that this error is not related to gii. Why don't your turn logging off (for now)?