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

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Oct 18, 2006 at 2:38 PM // reply »
124 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.


Oct 18, 2006 at 2:42 PM // reply »
124 Comments

@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.)


Oct 18, 2006 at 2:50 PM // reply »
7,572 Comments

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 :(


Oct 18, 2006 at 3:08 PM // reply »
124 Comments

@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.


Oct 18, 2006 at 5:09 PM // reply »
6 Comments

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.


Oct 19, 2006 at 7:24 AM // reply »
7,572 Comments

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.


Aug 28, 2008 at 11:08 PM // reply »
1 Comments

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?


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 22, 2010 at 7:43 AM
Terms Of Service / Privacy Policy Document Generator
Thankyou for this very helpful form. You've made my life much easier today. I'll have a look around your site... I'm sure there's some more good stuff here..Thanks Dave ... read »
Mar 22, 2010 at 7:21 AM
Encountered "(. Incorrect Select Statement, Expecting a 'FROM', But Encountered '(' Instead, A Select Statement Should Have a 'FROM' Construct.
I got this exception now. In case you're using var-es local struct, CF gives you couple of "new" exceptions: Encountered "local. and Encountered "id. Incorrect Select List, Incorrect select colum ... read »
Mar 22, 2010 at 3:08 AM
Ask Ben: Selecting XML Attributes Given Other XML Attributes
Thanks for the response. I finally discovered that I was getting this error because I had cfsetting enablecfoutputonly="yes" in Application.cfc, and was neither setting it to false elsewhere nor brac ... read »
Mar 21, 2010 at 8:57 PM
The Bourne Ultimatum Starring Matt Damon And Julia Stiles
late to the party, but my observation is this: rewatch carefully for the platonic nature of the relationship between nicki and jason. she never flirts with him. he never comes on to her. they alway ... read »
Mar 21, 2010 at 7:40 PM
Is Simulating User-Input Events With jQuery Ever A Good Idea?
A couple of things. One you embed the initial state of of more-info in the CSS. IMHO, that behavior should be in jQuery: moreInfo.hide(); It shows that the behavior your toggling and closing is mor ... read »
Mar 21, 2010 at 3:59 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Elliott, according to Ben's experiment, serializeJSON() doesn't access the private data by default - it doesn't even access the getHair() method - so trying to clone a Girl.cfc via serializeJSON/des ... read »
Mar 21, 2010 at 3:49 PM
Ask Ben: Javascript String Replace Method
I'm confused a bit by what you are asking, but if had this sentence: The color, red, is in the style statement; style: red;. and wanted to remove all or change all of the commas, colons, and semi-c ... read »
Mar 21, 2010 at 3:13 PM
Ask Ben: Javascript String Replace Method
I am trying to make a java program to count the number of times that these punctuation marks occur in a body of text: , : ; . ! - ' " ? / \ I am using this piece to ferret out the commas: numcommas ... read »