?
Solved

Coldfusion Site-wide and 404 error handlers not catching all errors

Posted on 2008-11-07
17
Medium Priority
?
1,191 Views
Last Modified: 2013-12-20
I've got a Site-wide Error handler and the missing template handler set up on the server, and the Site-wide handler does catch some errors, but not all of them. It seems to catch errors like incorrect variable names in the Coldfusion, but wouldn't catch an error returned from a MySql query, or an array entry undefined error. Instead of my error handlers it goes back to the default Coldfusion handlers.

I know the pages can be seen on the server at the correct paths as I've navigated to them manually, plus some of the errors are being caught but not all of them.

The biggest problem is that the errors not being caught are far more serious than the small ones that are.

It's Coldfusion 7 running on Red Hat.
0
Comment
Question by:comcar
  • 10
  • 7
17 Comments
 
LVL 8

Expert Comment

by:eszaq
ID: 22918973
It is most likely that exception type "database" is not covered in your error handling template. CHeck out this reference page:
http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001137.htm

If it you are not sure how to get use out of it, provide source code of your error handling template, please. And tell how your errors are handled - error template specified in CF admin? Or <CFERROR> tag inside your Application.cfm? Function onerror() inside Application.cfc?

http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001137.htm
0
 

Author Comment

by:comcar
ID: 22919840
It is the "Site-wide error handler page" set in the Coldfusion administrator.

I was under the impression setting the path to the template there would catch all errors.
And it's not just database errors, as stated above it also doesn't catch Java array object undefined errors.

It does catches loops timing out, empty or mismatched variable types.

I've attached the page code
<cftry>
	<cfmail 		
		from="tech2@comcar.co.uk"
		to="tech2@comcar.co.uk"
		type="html"		
		subject="Page Error">
		<strong>Comcar Page Error:</strong>
		<cfoutput>
		<br />
		#DateFormat(Now(),"dd/mm/yyyy")# @
                #TimeFormat(Now(),"hh:mm")#
		
		<p>
		Referer: #CGI.HTTP_REFERER#<br />
		IP Address: #CGI.REMOTE_ADDR#<br />
		Script Name: #CGI.SCRIPT_NAME#<br />
		Query String: #CGI.QUERY_STRING#<br />
		</p>
		
		<p>		
		<cfif isDefined('Session.userid')>
		User: #checkUser.username# - #checkUser.firstname# #checkUser.surname#
		<cfelse>
		No user info
		</cfif>
		</p>
 
		<p>
		<cftry>
	          <strong>Error Info:</strong>
		    <table>
		      <tr>
                        <td>Browser</td>
                        <td>#error.Browser#</td>
                      </tr>
                      <tr>
                        <td>Diagnostics</td>
                        <td>#error.Diagnostics#</td>
                      </tr>
                      <tr>
                        <td>generatedContent</td>
                        <td>#error.generatedContent#</td>
                      </tr>
                      <tr>
                        <td>message</td>
                        <td>#error.message#</td>
                      </tr>
                      <tr>
                        <td>rootCause</td>
                        <td>#error.rootCause#</td></tr>															
                      <tr>
                        <td>tagContext</td>
                        <td>#error.tagContext#</td>
                      </tr>
		      <tr>
                        <td>type</td>
                        <td>#error.type#</td>
                      </tr>
	            </table>
		<cfcatch>
		</cfcatch>
	        </cftry>
		</p>
	</cfmail>
	<cfcatch></cfcatch>
</cftry>

Open in new window

0
 

Author Comment

by:comcar
ID: 22919851
Sorry, that code follows this line.

The 2 chunks make up the body of the stie, sitting inside some DIVs on the standard site template
<p>The site has experienced an error and Technical Support has been notified. <br />Please press the back button on your browser and try using a different function of the web site</p>
<p>We apologise for any inconvenience</p>
 
<cfif isDefined('Session.userid')>
	<cfquery name="checkUser" datasource="#cdb#">
		SELECT firstname, surname, username FROM users 
                WHERE id = '#Session.userid#'
	</cfquery>
</cfif>
 
<!--- cfmail section follows on here directly --->

Open in new window

0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 8

Expert Comment

by:eszaq
ID: 22919861
number one:
you do not use <cfoutput> inside <cfmail> - this will generate coldfusion error on its own.  
0
 
LVL 8

Accepted Solution

by:
eszaq earned 1500 total points
ID: 22919895
Try this inside your <cfmail>:
<cfmail     from="tech2@comcar.co.uk"
            to="tech2@comcar.co.uk"
            type="html"             
            subject="Page Error">
 
 <p>             
  <cfif isDefined('Session.userid')>
	User: #checkUser.username# - #checkUser.firstname# #checkUser.surname#
  <cfelse>
	No user info
  </cfif>
 </p>
 <DL>
	<CFLOOP COLLECTION="#Error#" ITEM="Key">
      <CFIF IsSimpleValue(Error[Key]) AND NOT (Key is "GeneratedContent" OR Key is "StackTrace")><!---  --->
         <DT><B>#Key#</B> - </DT><DD>#Error[Key]#</DD>
      <CFELSEIF IsArray(Error[Key])>
         <DT><B>#Key#</B></DT><DD><OL>
         <CFLOOP INDEX="i" FROM="1" TO="#ArrayLen(Error[Key])#">
            <LI> 
               <CFLOOP COLLECTION="#Error[Key] [i]#" ITEM="Key2">
              <B>#key2#</B> - #Error[Key] [i][Key2]#<br />
               </CFLOOP>
         </CFLOOP>
         </OL>
         </DD>
      </CFIF>
	</CFLOOP>
 </DL>
 
</cfmail>

Open in new window

0
 

Author Comment

by:comcar
ID: 22921685
I'll give that a try but the template has to have loaded for these changes to take effect anyway.

Could you please explain how this will make a difference please? Also the <cfoutput> tags inside <cfmail> have not thrown an error, and I am aware they are mismatched, that was a typo.
0
 
LVL 8

Expert Comment

by:eszaq
ID: 22921758
<cfoutput> tags inside <cfmail> had not thrown error because it was inside <cftry>block. This is what <cftry> is for. If code is erroneus, coldfusion executes whatever is inside <cfcatch>, which is nothing in your template.

In terms of "give it a try" - just do it. I gave you generic code that will send you email with complete information about your error.
0
 
LVL 8

Expert Comment

by:eszaq
ID: 22964973
Did you figure what is causing your errors? Tried to upload the code I sent? It's an excellent tool.  You'll be able see complete error info including line numbers in your code.
0
 

Author Comment

by:comcar
ID: 22976294
What I had meant was that emails are being sent, whilst inside the <cfoutput> tags. I have received some emails regarding the errors I mentioned, it's just not all of them.

I've used your code as suggested and it does give a better more complete error report, but so far it's still just  catching the small errors I was already receiving before, I'm going to have to wait and see if it catches one of the bigger more serious errors.

I'll post back as soon as I know if it made the difference.
0
 
LVL 8

Expert Comment

by:eszaq
ID: 22976717
There are different types of errors that are handled differently. Often by different templates. What are your setting in Coldfusion Administrator? What does your Application.cfm look like? Does it have CFERROR tags to handle different types of errors?
Did you provide complete code of your error handling template?
0
 
LVL 8

Expert Comment

by:eszaq
ID: 22976819
Besides, if you have cftry-cfcatch blocks on your pages  - error template will not run. You'll have to specify action inside your <cfcatch>. Just do global search for "<cftry" in your code and add reporting code to your <cfcatch> blocks.
0
 

Author Comment

by:comcar
ID: 22977214
There are no <cftry><cfcatch> blocks in my application.cfm.

The cftry and catch built into the error template are there on the chance that the error reporting itself causes an error, in which case a blank template page should appear at least with out headers and footers.

The Coldfusion Administrator page has the path name to this page I'm talking about here, and I was under the impression that putting the path there, in the CF Administrator would catch ALL errors across the site and display my error message page.

I understand that the <cfcatch> tag will do nothing if it is left blank, the point is that the page is not even loading in some cases, so the cftry is not failing in order for the cfcatch to post a blank body to the screen.
0
 
LVL 8

Expert Comment

by:eszaq
ID: 22977262
>>> There are no <cftry><cfcatch> blocks in my application.cfm

I meant for you to do global search of your application - all the templates, not just Application.cfm. If for exaple order.cfm has cftry-cfcatch block in it - you error teplate will not run, because error is already handled inside template.

Idea of error template is to handle uhcaught errors.
0
 

Author Comment

by:comcar
ID: 23041071
Argh no it didn't work after all!!

I have been recieving some error messages via email as I was before anyway the introduction of the new code suggested by eszag, but I just ran into an error on the site that did not show the site wide error template that is set in the Coldfusion Administrator,

I just got the standard ugly white and blue Coldfusion error template and received no email.

It is obvious that just putting the file path in the Coldfusion Administrator does not actually catch all errors. Is anyone aware of some further settings that can be adjusted so that the Site-Wide Error template will actually work for all errors?
0
 
LVL 8

Expert Comment

by:eszaq
ID: 23043472
1. Did you post complete source of your error handling template? Or there is more code (that might be erroneous)?
2. Does your Application.cfm have <cferror> tag, which possibly points to another template that might have errors in it?
3. What exactly did your standard white and blue error "that did not show the site wide error template" say? Unless you provide more info, it's hard to answer.
0
 

Author Comment

by:comcar
ID: 23048154
1) Full source attached
2) There are no <cferror> tags used in the site, I only use the site-wide one in the Administrator
3) The error was  "Duplicate entry for key XXXXXX" when trying to do an insert into the database. I don't have the exact error here, sorry, when it comes up again I'll paste it.

Cheers


<cfparam name="pathToRoot" default="">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/newcar/Templates/newcar050801.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<cfoutput>
<cfinclude template="#pathToRoot#assets/code/channelDecoder.cfm">
<cfparam name="URL.clk" default="1">
#channelDecoder_init(URL.clk)#
<cfif #channel_includeSetup# IS NOT "">
	<cfinclude template="#pathToRoot##channel_includeSetup#">
</cfif>
</cfoutput>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<cfset channelInt_pageTitle="Comcar.co.uk">
<title><cfoutput>#channel_titlePrepend# #channelInt_pageTitle#</cfoutput></title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<cfparam name="metadesc" default="Company car tax Calculator">
<cfparam name="metakey" default="Company car tax van fuel new benefit Co2 Calculator UK petrol diesel">
<cfoutput>
<meta name="description" content="#metadesc#" />
<meta name="keywords" content="#metakey#" />
</cfoutput>
<meta http-equiv="pragma" content="no-cache" /> <!--Netscape -->
<cfoutput>
<cfinclude template="#pathToRoot#assets/code/iHead.cfm">
<cfinclude template="#pathToRoot#standardNames.cfm">
<link href="/newcar/assets/styles/externalStyles.css" rel="stylesheet" type="text/css" />
<cfif #channel_styleSheet# IS NOT "">
	<link href="/newcar/#channel_styleSheet#" rel="stylesheet" type="text/css" />
</cfif>
</cfoutput>
<!--- code to include google ad setup script --->
<cfparam name="showGoogleAd" default="false">
<cfif showGoogleAd>
	<script type="text/javascript" src="http://partner.googleadservices.com/gampad/google_service.js"></script>
	<script type="text/javascript">
	GS_googleAddAdSenseService("ca-pub-9876074324849028");
	GS_googleEnableAllServices();
	</script>
</cfif>
<cfif #channel_javascript# IS NOT "">
	<cfinclude template="/newcar/channels/#channel_javascript#" />
</cfif>
<!-- InstanceBeginEditable name="head" -->
 
<!-- InstanceEndEditable -->
</head>
 
<body class="default borderless">
<div class="main">
	<cfinclude template="#pathToRoot##channel_includeHeader#">
	<div class="main-left">
			<!-- InstanceBeginEditable name="innertitle" -->
	<cfset channelInt_pageTitle="<h1 class='title'>ComCar <span class='red'>apologies for any inconvenience</span></h1>">
<!-- InstanceEndEditable -->
			<cfinclude template="#pathToRoot##channel_includeNav#">
			<div class="body">
			<!-- InstanceBeginEditable name="body" -->
		<p>The site has experienced an error and Technical Support has been notified. <br />Please press the back button on your browser and try using a different function of the web site</p>
		<p>We apologise for any inconvenience</p>
		
		<cfif isDefined('Session.userid')>
			<cfquery name="checkUser" datasource="#cdb#">
				SELECT firstname, surname, username FROM users WHERE id = '#Session.userid#'
			</cfquery>
		</cfif>
		
		<cftry>
		<cfmail     from="tech2@comcar.co.uk"
            to="tech2@comcar.co.uk"
            type="html"             
            subject="Page Error">
 
	 <p>             
	  <cfif isDefined('Session.userid')>
			User: #checkUser.username# - #checkUser.firstname# #checkUser.surname#
	  <cfelse>
			No user info
	  </cfif>
	 </p>
	 <DL>
        <CFLOOP COLLECTION="#Error#" ITEM="Key">
      <CFIF IsSimpleValue(Error[Key]) AND NOT (Key is "GeneratedContent" OR Key is "StackTrace")><!---  --->
         <DT><B>#Key#</B></DT>
		 <DD>#Error[Key]#</DD>
      <CFELSEIF IsArray(Error[Key])>
         <DT><B>#Key#</B></DT><DD><UL>
         <CFLOOP INDEX="i" FROM="1" TO="#ArrayLen(Error[Key])#">
            <LI> 
               <CFLOOP COLLECTION="#Error[Key] [i]#" ITEM="Key2">
              <B>#key2#</B> - #Error[Key] [i][Key2]#<br />
               </CFLOOP>
         </CFLOOP>
         </UL>
         </DD>
      </CFIF>
        </CFLOOP>
	 </DL>
 
</cfmail>
	<cfcatch></cfcatch>
	</cftry>
<!-- InstanceEndEditable -->
			</div>
			<!--- execute javascript before page load completes (ads) --->
			<script language="javascript" type="text/javascript">
			<!--//
			//-->
			</script>
			<!--- dynamically pull in ad & bottomnav --->
			<cfinclude template="#pathToRoot##channel_includeFooter#"><br />
			<cfinclude template="#pathToRoot##channel_includeBottomnav#">
	</div>
	<div class="main-right">
			<cfinclude template="#pathToRoot##channel_includeSkyscraper#">
	</div>
</div>
</body>
<!-- InstanceEnd --></html>

Open in new window

0
 
LVL 8

Expert Comment

by:eszaq
ID: 23054260
You have an awful lot of ColdFusion code in your error handling template. There are quite a few places where your plan can get messed up.

First:
<cfinclude template="#pathToRoot#assets/code/channelDecoder.cfm">
What's is in there? If anything goes wrong inside this include, your error template will stop right there, your user will see "standard ugly white and blue Coldfusion error template", and you will never receive the email report.

Same story with these includes that are supposed to be processed before the code that sends error message to you:
<cfinclude template="#pathToRoot#assets/code/iHead.cfm">
<cfinclude template="#pathToRoot#standardNames.cfm">
<cfinclude template="#pathToRoot##channel_includeHeader#">
<cfinclude template="#pathToRoot##channel_includeNav#">

I am not even mentioning includes below your <cfmail> tag. They might cause error (and ugly white and blue page), too. But it's most likely that email will go out before the page breaks.

Next. Your checkUser query is not wrapped inside separate <cftry> block. If you are having problems with your database connection (stuff happens) your error template will be absolutely useless until the problem is resolved. Page will break every time before <cfmail> tag.

In order for your side wide error template to work you have to make your script as safe as possible. Eliminate as much of ColdFusion code as you can. It is most likely that you do not need all your HTML headers/footers to be generated dynamically - I seriously doubt that your website design changes very frequently. Just open your homepage (or any other page that has the same layout as your error page), select "view source" option, copy HTML code and use it inside your error template.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question