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

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.
comcarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

eszaqCommented:
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
comcarAuthor Commented:
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

comcarAuthor Commented:
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

Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

eszaqCommented:
number one:
you do not use <cfoutput> inside <cfmail> - this will generate coldfusion error on its own.  
eszaqCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
comcarAuthor Commented:
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.
eszaqCommented:
<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.
eszaqCommented:
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.
comcarAuthor Commented:
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.
eszaqCommented:
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?
eszaqCommented:
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.
comcarAuthor Commented:
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.
eszaqCommented:
>>> 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.
comcarAuthor Commented:
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?
eszaqCommented:
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.
comcarAuthor Commented:
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

eszaqCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.