Strange ColdFusion Application.cfc Error Update - It Works AND It Breaks

Posted October 18, 2006 at 12:23 PM

Tags: ColdFusion

So, I have an update to my very strange Application.cfc errors. I took the advice of some people and I tried moving the code into new files in new directories to see if it was a template caching issue. Now, I only have an Application.cfc, and index.cfm, and trace.txt files. The methods in the Application.cfc ONLY do a CFFile / Append to the trace.txt file so I can see if and when system events fire. The index.cfm ONLY dumps out the APPLICATION scope. There is no other code being run here, no other error handling.

Here is the updated Application.cfc

 Launch code in new window » Download code as text file »

  • <cfcomponent
  • displayname="Application"
  • output="true"
  • hint="Handle the application.">
  •  
  •  
  • <cfscript>
  •  
  • THIS.Name = "App Event Testing 2";
  • THIS.ApplicationTimeout = CreateTimeSpan( 0, 0, 0, 15 );
  • THIS.SessionManagement = true;
  • THIS.SessionTimeout = CreateTimeSpan( 0, 0, 0, 10 );
  • THIS.LoginStorage = "SESSION";
  • THIS.SetClientCookies = true;
  •  
  • </cfscript>
  •  
  •  
  • <cfsetting
  • requesttimeout="10"
  • showdebugoutput="false"
  • enablecfoutputonly="false"
  • />
  •  
  •  
  • <cffunction name="OnApplicationStart" access="public" returntype="boolean" output="true"
  • hint="Fires when the application is first created.">
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnApplicationStart"
  • addnewline="true"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn true />
  • </cffunction>
  •  
  •  
  • <cffunction name="OnSessionStart" access="public" returntype="void" output="true"
  • hint="Fires when the session is first created.">
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnSessionStart"
  • addnewline="true"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  •  
  • <cffunction name="OnRequestStart" access="public" returntype="boolean" output="true"
  • hint="Fires when prior to page processing.">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="TargetPage" type="string" required="yes" />
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnRequestStart"
  • addnewline="true"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn true />
  • </cffunction>
  •  
  •  
  • <cffunction name="OnRequest" access="public" returntype="void" output="true"
  • hint="Fires after pre page processing is complete.">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="TargetPage" type="string" required="yes" />
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnRequest"
  • addnewline="true"
  • />
  •  
  • <!--- Include the requested page. --->
  • <cfinclude template="#ARGUMENTS.TargetPage#" />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  •  
  • <cffunction name="OnRequestEnd" access="public" returntype="void" output="true"
  • hint="Fires after the page processing is complete.">
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnRequestEnd"
  • addnewline="true"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  •  
  • <cffunction name="OnSessionEnd" access="public" returntype="void" output="true"
  • hint="Fires when the session is terminated.">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="SessionScope" type="struct" required="true" />
  • <cfargument name="ApplicationScope" type="struct" required="false" default="#StructNew()#" />
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnSessionEnd : [ID - #ARGUMENTS.SessionScope.CFID#] [TOKEN - #ARGUMENTS.SessionScope.CFTOKEN#]"
  • addnewline="true"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  •  
  • <cffunction name="OnApplicationEnd" access="public" returntype="void" output="false"
  • hint="Fires when the application is terminated.">
  •  
  • <cfargument name="ApplicationScope" type="struct" required="false" default="#StructNew()#" />
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnApplicationEnd : [NAME - #ARGUMENTS.ApplicationScope.ApplicationName#]"
  • addnewline="true"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  •  
  • <cffunction name="OnError" access="public" returntype="void" output="true"
  • hint="Fires when an exception occures that is not caught by a try/catch.">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="Exception" type="any" required="true" />
  • <cfargument name="EventName" type="string" required="false" default="" />
  •  
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './trace.txt' )#"
  • output="OnError : [#ARGUMENTS.Exception.Message# - #ARGUMENTS.Exception.Type#] #ARGUMENTS.Exception.Detail#"
  • addnewline="true"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  • </cfcomponent>

Here is the output that it produces:

OnApplicationStart
OnSessionStart
OnRequestStart
OnRequest
OnRequestEnd
OnSessionEnd : [ID - 43666] [TOKEN - 32723233]
OnError : [Event Handler Exception. - Expression] An exception occurred when invoking a event handler method from Application.cfc The method name is: onSessionEnd.
OnApplicationEnd : [NAME - App Event Testing 2]
OnError : [Event Handler Exception. - Expression] An exception occurred when invoking a event handler method from Application.cfc The method name is: onApplicationEnd.

As you can see, the OnSessionEnd and OnApplicationEnd methods are both firing and both can successfully reference their passed in scope arguments. However, both of them seem to fire an OnError even of type "Expression". I am not going to be too concerned with this, I suppose, as all the events ARE firing. I just wish I knew why error was firing as well.

Thanks for all your help and if any one sees what's going on, please let me know. Thanks!

Download Code Snippet ZIP File

Comments (7)  |  Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




Reader Comments

@Ben:

I'm going to take a guess and say it's because your CFRETURN tags are returning neither true or false. Try leaving the CFRETURN tags or setting their values to an actual boolean value.

Posted by Dan G. Switzer, II on Oct 18, 2006 at 2:38 PM


@Ben:

I just ran that code under CFMX 7,0,2,142559 and here's what my log looks like after several runs:

OnApplicationStart
OnSessionStart
OnRequestStart
OnRequest
OnRequestEnd
OnSessionEnd : [ID - 2100] [TOKEN - 11429582]
OnSessionStart
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnSessionEnd : [ID - 2100] [TOKEN - 11429582]
OnApplicationEnd : [NAME - App Event Testing 2]
OnApplicationStart
OnSessionStart
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd
OnRequestStart
OnRequest
OnRequestEnd

(I just rapidly hit refresh on my browser.)

Posted by Dan G. Switzer, II on Oct 18, 2006 at 2:42 PM


Dan,

I tried taking out the CFReturn statements at one point and it didn't seem to matter. The test you just ran, did you leave those in?

Maybe it's just my machine then :(

Posted by Ben Nadel on Oct 18, 2006 at 2:50 PM


@Ben:

I ran the code as-is. A couple of notes:

1) Try copying and pasting the code from this blog--to make sure there aren't any funky characters in your template (I've seen templates behave strangely when saved in one charset that actually contained invalid chars.)

2) Check the version of your server. Perhaps you're missing a patch (or I am) and it's something w/the version of CFMX you're running. I'm using teh DevNet edition.

Posted by Dan G. Switzer, II on Oct 18, 2006 at 3:08 PM


Just so you don't think it is just you, I was getting the exact same error several months ago with similar code. Never found a solution.

Here is the code I used:
<cffunction name="onApplicationEnd" returnType="void" output="false">
<cfargument name="applicationScope" required="true">
</cffunction>

<cffunction name="onSessionEnd" returnType="void" output="false">
<cfargument name="sessionScope" type="struct" required="true">
<cfargument name="appScope" type="struct" required="false">
</cffunction>

It didn't happen on my dev machine, it was only on the live site.

I still had one of the error dump emails:
TagContext array [empty]
Type java.lang.NullPointerException
Type: Expression Template: C:\dev\ozarka\Application.cfc? Tag Context:
array [empty]
Exception:
struct
Detail An exception occurred when invoking a event handler method from Application.cfc The method name is: onSessionEnd.

Posted by Scott Pinkston on Oct 18, 2006 at 5:09 PM


Scott, thank you for making me feel that perhaps I wasn't a raving lunatic :)

Dan,
Yeah, copy and paste still the same issue. I am running Enterprise version 7,0,1,116466. Looks like we are missing the 7,0,2 patch. Hmmm, that might be it.

Posted by Ben Nadel on Oct 19, 2006 at 7:24 AM


I started getting this error after doing a structclear on the session and application scope. I removed the function, onRequestStart and am now getting the error in a different template all together.

Did you ever figure out a direct cause for this error?

Posted by Johnny on Aug 28, 2008 at 11:08 PM


Post Comment  |  Ask Ben


Home   |   Web Log   |   ColdFusion   |   Projects   |   Resume   |   Job Form   |   Search   |   Contact
Epicenter Consulting - Custom Software Solutions for Business Evolution HostMySite.com - The Leader In ColdFusion Hosting