Custom page Error doesn't work. (in production always return code 500) - twig

So i'm working on a project and i wanted to make custom error page like 404 500 ...
So i read on symfony documentation that all i have to do is composer twig-pack, then add the error404.html.twig in this tree directory \templates\bundles\TwigBundle\Exception. To finish I have to change my .env in prod to see my beauty error page.
But when i try to type a wrong url expecting to get my 404, instead, i got a 500 (the basic error page from symfony).
I checked my logs and i found that i got this Critical Error :
[2021-07-14T08:35:15.194689+00:00] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET https://micro59/dejifosd"" at C:\wamp\www\Projects\micropro\vendor\symfony\http-kernel\EventListener\RouterListener.php line 136 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET https://micro59/dejifosd\" at C:\\wamp\\www\\Projects\\micropro\\vendor\\symfony\\http-kernel\\EventListener\\RouterListener.php:136)\n[previous exception] [object] (Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0): No routes found for \"/dejifosd/\". at C:\\wamp\\www\\Projects\\micropro\\vendor\\symfony\\routing\\Matcher\\Dumper\\CompiledUrlMatcherTrait.php:70)"} []
[2021-07-14T08:35:15.229712+00:00] php.CRITICAL: Uncaught Error: Symfony\Bridge\Twig\Extension\RoutingExtension::getPath(): Argument #1 ($name) must be of type string, null given, called in C:\wamp\www\Projects\micropro\var\cache\prod\twig\d5\d51256555fdd9ed9db40150aba9ba2f8325c04e57ae45e60937191a29447ddd2.php on line 37 {"exception":"[object] (TypeError(code: 0): Symfony\\Bridge\\Twig\\Extension\\RoutingExtension::getPath(): Argument #1 ($name) must be of type string, null given, called in C:\\wamp\\www\\Projects\\micropro\\var\\cache\\prod\\twig\\d5\\d51256555fdd9ed9db40150aba9ba2f8325c04e57ae45e60937191a29447ddd2.php on line 37 at C:\\wamp\\www\\Projects\\micropro\\vendor\\symfony\\twig-bridge\\Extension\\RoutingExtension.php:46)"} []
[2021-07-14T08:35:15.232242+00:00] request.CRITICAL: Uncaught PHP Exception TypeError: "Symfony\Bridge\Twig\Extension\RoutingExtension::getPath(): Argument #1 ($name) must be of type string, null given, called in C:\wamp\www\Projects\micropro\var\cache\prod\twig\d5\d51256555fdd9ed9db40150aba9ba2f8325c04e57ae45e60937191a29447ddd2.php on line 37" at C:\wamp\www\Projects\micropro\vendor\symfony\twig-bridge\Extension\RoutingExtension.php line 46 {"exception":"[object] (TypeError(code: 0): Symfony\\Bridge\\Twig\\Extension\\RoutingExtension::getPath(): Argument #1 ($name) must be of type string, null given, called in C:\\wamp\\www\\Projects\\micropro\\var\\cache\\prod\\twig\\d5\\d51256555fdd9ed9db40150aba9ba2f8325c04e57ae45e60937191a29447ddd2.php on line 37 at C:\\wamp\\www\\Projects\\micropro\\vendor\\symfony\\twig-bridge\\Extension\\RoutingExtension.php:46)"} []
Aaaaaaaand thats where i'm stuck. I try many things (Composer update, Clear cache...) but nothing change. If someone would have the kindness to help me that would be much appreciate it.

The class & method in the error message, RoutingExtension::getPath(), defines a Twig function - path(). Your error404.html.twig file uses that function but doesn't have the required first parameter ('name', the route name) - or the value that is being passed to it, is null.
How to Customize Error Pages has a simple error-page template, and has a sample path/route-name {{ path('homepage') }}.
You can get a list of the routes you have available so far with bin/console debug:router - it must be known to the framework, or it will throw an error about an unknown route.
It also has a .yaml you can use to make the error pages available in development (your controller is fine, this would be a bit cleaner and easier - and would only be available in development because of the path within the config/ directory is only read when your APP_ENV variable is 'dev').
If you have not already, composer require debug-pack and any errors - including on your '/error404' page will show a 'big friendly error page', should also add a lot of useful information - often including showing the file and line in the twig template.
In this particular instance, because of the type of error, it can't as it's deep in the Twig library internals (and comes from the PHP type-system, not an error found directly by Symfony or Twig) - but it will have a link in the stack trace to show the compiled twig template (in a randomly named file in ./var/cache/dev/twig/../.......php) and it shows where in the twig template it's calling the ->getPath(); - so you'll be able to track it down in the actual .twig file (it adds comments for the line number within the template to help).

Related

nodejs - TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer - when using callback response with http.request

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type number
at Function.from (buffer.js:305:9)
In quite a number of times : getting an [ERR_INVALID_ARG_TYPE] error implies that a certain argument or parameter is needed for the node app or which ever app you are attempting to run, to run properly.
SCENARIO #1 : .env []
A few checks to look out for example; in the case of parameters being defined into .env file for the (node) application to function :
Check if the .env file has been properly defined or created for the app
Are the needed parameters for the node app to work all well defined in your ".env" file ?
If the parameters are not there define them, example :
PORT=3000
PATH=/home/data/images/
HOST=http://localhost
DB_NAME=test_db
And to access them :
process.env.PORT
process.env.PATH
process.env.HOST
process.env.DB_NAME
With the above done, any errors in relation to [ERR_INVALID_ARG_TYPE] should clear when now you issue your command in the terminal to run the node application.
SCENARIO #2 : http.request (related)
Please I definitely encourage you to check your code again, there might be some parameter or argument you are required to have defined or should have set in place before the node app can run properly.
You may refer to SCENARIO #1 to make sure all or any parameter or argument is properly defined and try running the app again.
I would love to know if the suggested answer above was helpful or if you did something else to fix it, do share. Thanks and best wishes.

Page Type of a class name not found exception

I am new to Kentico and going through the Kentico 12 MVC Training Course using the MedioClinic sample project. On running the MVC project for live site I am getting the below error. Could someone please help me with this.
Server Error in '/Kentico12_MedioClinic' Application.
Page type with 'MedioClinic.HomeSection' class name not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: CMS.DocumentEngine.DocumentTypeNotExistsException: Page type with 'MedioClinic.HomeSection' class name not found.
Source Error:
Line 38: {
Line 39: var query = DocumentHelper.GetDocuments();
Line 40:
Line 41: // Loads the latest version of documents as preview mode is enabled
Line 42: if (SiteContext.IsPreviewEnabled)
Source File: C:\Users\A0808038\Desktop\Kentico\training-kentico-k12-master\training-kentico-k12-master\Business\Services\Query\DocumentQueryService.cs Line: 40
Thanks in Advance
From the admin area go to edit the page type "MedioClinic.HomeSection" and click on the vertical tab "Code" then from there click on generate code, so those are saved physically on the /CMS/Old_App_code folder from the WebApp solution.
Copy that generated file to your MVC project, add the correct using to your class and that should fix the issue.

Jade Unexpected block Error

NOTE: Similar to this question, but not the same.
I have an expressjs node website (WIP), but I keep getting the follwoing error:
Warning: Unexpected block "head" on line 3 of \src\dynamic\views\index.jade. This block is never used. This warning will be an error in v2.0.0
Warning: Unexpected block "body" on line 5 of \src\dynamic\views\index.jade. This block is never used. This warning will be an error in v2.0.0
My src\dynamic\views\index.jade:
extends _includes/head/head
block head
title Skool - On Our Way!
block body
extends _includes/navbars/topNav
The _includes/navbars/topNav.jade file is just a basic jade file depicting a simple bootstrap navbar, so I will omit it.
_includes/head/head:
doctype html
html
head
link(rel="styleSheet" href="css/main.css")
script(src="js/app.js")
block head
body
block body
Now when I visit localhost:3000, I am greeted with my compiled jade file, except the <head> element is empty, so there are no css links! Checking the console log I see the previously mentioned error/warning.
What am I doing wrong?
Many thanks to #Molda for pointing me in the right direction. (S)he said:
I think that you should only use extends once in your view. Use include for topNav.
So as soon as I replaced that one extends it worked, and my <head> element was no longer empty.
Now I cannot find anything that documents the "you can only use extends once" rule, but as far as I can gather only the last extends is used.

XPages Custom Error Page - get error message and line

I'm trying to generate a custom error page for my xpages. I googled a lot of solutions and so far I get an error page telling me, that an error occured.
But I can't get the information what exactly happened (in this case the error is, that an "doc" has to be saved, but i named the variable "docs" just to get error).
All I do is:
var errObj = requestScope.error;
output = errObj.getCause().getErrorPropertyId();
output = errObj.getCause().getComponentId();
As soon as I try to call getExpressionText() I get an error 500.
How do I get the information, where the error happened (line number) and the variable that caused the error? - just like I do using the standard error page.
The error line and details are not easily accessible from requestScope.error. If you look at the source code for the latest release of Mark Leusink's Debug Toolbar, you'll see he's parsing the stack trace to get the details.
However, you can access all the relevant information using the underlying Java class for the SSJS exception - com.ibm.jscript.InterpretException using getErrorLine(). The getLocalizedMessage() method gets the error detail that usually starts "Script interpreter error". The getExpressionText() method retrieves the line that threw the error.
If you take a look at the XPages OpenLog Logger project I put on OpenNTF, that's what I use to log full details to OpenLog. http://www.openntf.org/Internal/home.nsf/project.xsp?action=openDocument&name=XPages%20OpenLog%20Logger
You can see the source code of the OpenLogPhaseListener which uses those methods here: https://github.com/paulswithers/openlogjava/blob/master/OpenLogJava/WebContent/WEB-INF/src/com/paulwithers/openLog/OpenLogPhaseListener.java
Even if you're not a Java expert, from use of SSJS the key parts should be understandable. Line 84 captures uncaught exceptions - when XPages routes to the default error page. That uses the methods I mentioned.
Lines 98 to 105 are the ones that log out all the details if you just use a catch block, passing OpenLogBean.addError(e, this) where e is the error object and this is the component the error occurs on. error.getError() in the Java code retrieves that error object. To get the typeahead in SSJS you'll need to use catch(e:com.ibm.jscript.InterpretException) I believe.
I haven't tested this, I've just working back from what I used for the project on OpenNTF.
Have a look at this XSnippet by Tony McGuckin: http://openntf.org/XSnippets.nsf/snippet.xsp?id=custom-error-page-cw-cause-and-stacktrace-information. It uses the following to output details on the error:
var output = requestScope.error.toString()+"\n\n";
if(requestScope.error instanceof com.ibm.xsp.exception.XSPExceptionInfo){
var codeSnippet = requestScope.error.getErrorText();
var control = requestScope.error.getErrorComponentId();
var cause = requestScope.error.getCause();
output += "In the control : " + control + "\n\n";
if(cause instanceof com.ibm.jscript.InterpretException){
var errorLine = cause.getErrorLine();
var errorColumn = cause.getErrorCol();
output += "At line " + errorLine;
output += ", column " + errorColumn + " of:\n";
}else{
output += "In the script:\n";
}
output += codeSnippet;
}
return output;
For now I've dealt with this problem by using the Debug Toolbar and the OpenLog Database.
If an error occurs the user only gets a custom error page (using the example of the Debug Toolbar) with the information, that something went wrong. So he does not have to bother with any other problems or even the Stack Trace. But at the same moment he gets the error page, the error is logged in our Log-Database with all informations needed (like line, exact error message etc.).
I've also implemented an "Report this problem" Link-Button to create a new E-Mail containing important information about the session the user is currently in.

Derbyjs TEMPLATE ERROR

I just started trying out Derbyjs, and I already ran into a problem. I can't find any support for this error, and most likely is some dumb mistake i'm making.
I'm trying to render a view, following the example from the www.derbyjs.com documentation.
My app is as simple as this:
var app = require('derby').createApp(module);
app.get('/', function (page, model) {
page.render('home');
});
My views are composed by two files.
"index.html"
<import: src="home">
<Body:>
Default page content
"home.html"
<Body:>
Welcome to the home page
I get the following error whenever the page is rendered:
TEMPLATE ERROR
Error: Template import of 'home'... ...can't contain content
As you can see, it is a very simple example. What am I missing?
I get that error even if I have the "home.html" file empty.
Well, I got the answer from one of the developers.
It seems like there was a subtle bug in the Template Parser that probably has already been fixed.
Having a whitespace or linebreak in front of
<import: src="home">
was causing the parser to raise the error. Writing
<import: src="home"><Body:>
solved the issue.

Resources