Quick and dirty debugging tip for Flex/ColdFusion

This post is more than 2 years old.

There are multiple methods of debugging applications, including the very cool FusionDebug, log files, ServiceCapture, and the debugging rolled into Flex Builder 2 itself. Here is a quick tip for another method to use. It's ugly - but effective.

Modify your onError to dump the errors and log to a file like so:

<cffunction name="onError" returnType="void" output="false"> <cfargument name="exception" required="true"> <cfargument name="eventname" type="string" required="true"> <cfset var temp = "">
&lt;cflog file="my app" text="#arguments.exception.message#, #arguments.exception.detail#"&gt;
&lt;cfsavecontent variable="temp"&gt;
&lt;cfdump var="#arguments#"&gt;
&lt;cffile action="write" file="c:\myapp.html" output="#temp#"&gt;
&lt;cfdump var="#arguments#"&gt;&lt;cfabort&gt;


I wrapped a dump of the arguments (which contain my exception) and simply save it to the C drive as an HTML file. I then have this file open in my browser. As I debug, I can simply reload the tab in Firefox to see what the latest error was.

I find this especially useful when the exception message is a bit too vague. With the dump I get the full trace of files where the error occurred.

Let me be absolutely clear: Do not use this code in production. It isn't nice. It doesn't play well with others. It runs with scissors. You get the idea. But I thought I'd share.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Tom Mollerus posted on 1/30/2007 at 2:11 AM

OK, I'll take the risk of sounding naive: what exactly are the dangers of using cflog in your error code in a production system? This seems like a pretty good tactic to me.

Comment 2 by todd sharp posted on 1/30/2007 at 2:25 AM

Its been a while since I worked in Flex, but I also liked to throw a dump method into components when developing a flex app. The method looked like this:

<cffunction name="dump" output="false" access="remote" returntype="void" hint="i dump">
<cfargument name="content" type="any">
<cfset var theDir = getDirectoryFromPath(expandPath("*.*"))>
<cfset var theFile = theDir & createUUID() & ".xls">
<cfset var theOutput = "">
<cfsavecontent variable="theOutput"><cfdump var="#arguments#"></cfsavecontent>
<cffile action="write" file="#theFile#" output="#theOutput#"/>

Again, not the prettiest but its a similar idea for taking a look at what a certain grid or flex data element contained in a familiar format (cfdump).

I would like to get my hands on Nimers debug panel if I get back into Flex development anytime soon.

Comment 3 by Raymond Camden posted on 1/30/2007 at 2:28 AM

Tom, I didn't mean the cflog, but the cffile operation. That was the main point of the blog post. (Remember I said that cflog was text based?) If that isn't clear, let me know.

Comment 4 by Clint Tredway posted on 1/30/2007 at 2:31 AM

I normally use cfmail and dump the arguments and cfcatch scope into an HTML email and that has been the best way for me. I have been doing it this way since I started doing RIA's with Flash MX.

Comment 5 by Justice posted on 1/30/2007 at 2:35 AM


I did this very same thing a while back, only I did my file dump like this:

<cffile action="write" file="c:\debug\#replace(replace(xmlFormat(CGI.Script_Name), '/', '_', 'ALL'), '.', '_', 'ALL')#.html" output="#mydbgOutput#">

then, I got file names like this: rootdir_subdir_dubdir_file.cfm.html

then I could look at all my templates being called and what debug output they had. Like you said, its kinda resource heavy writing files for each request, but makes debugging easier, and wont break web layouts with popups or divs.

Comment 6 by Raymond Camden posted on 1/30/2007 at 2:40 AM

Clint, mail is what I normally do in production. But for dev - this worked out well as I didn't have to wait for the mail to arrive. Plus - I don't have a mail server on this local box.

Comment 7 by Clint Tredway posted on 1/30/2007 at 2:45 AM

Very true, I do a file dump when I dont have access to a mail server, but when I do, even in dev, I do mail dumps. I have also been using FlashTracer in FireFox to get errors as well.

Comment 8 by Danlance posted on 1/30/2007 at 5:55 PM


I am using exactly the same technique ATM for debugging functions called from an Async event gateway.

I am using CFLog throughout the app to log events and errors to a log file, but there are definately times that having the full stack trace etc. is invaluable.

Again, as other people have mentioned, we use cfdump / cfmail within live apps, but during initial dev, having to wait ~3 minutes to see the error, is not acceptable :)

Comment 9 by Mike Collins posted on 1/31/2007 at 6:23 PM

I did something similar, although I wrapped the error in a cfdocument tag with a filename attribute and saved as a swf. I then was able to pull in the swf right into my flex app.

Comment 10 by Raymond Camden posted on 1/31/2007 at 6:42 PM

Well that is pretty nifty there Mike. What a cool idea!

Comment 11 by Sid Wing posted on 2/1/2007 at 4:33 AM

To keep from having to maintain differing versions from my testbed to my production, I could make a minor modification to that code (see below) which would only create the file on my testbed (ie. localhost) environment.

I could also throw in a "cfelse" that would run the "cfdump" to cfmail if it is NOT on the testbed. Used this methodology when I was working with application.cfm at Discovery. Worked well.

<cffunction name="onError" returnType="void" output="false">
<cfargument name="exception" required="true">
<cfargument name="eventname" type="string" required="true">
<cfset var temp = "">

<cflog file="my app" text="#arguments.exception.message#, #arguments.exception.detail#">

<cfif cgi.servername is "localhost"><!--- Sid's Mod --->
<cfsavecontent variable="temp">
<cfdump var="#arguments#">
<cffile action="write" file="c:\myapp.html" output="#temp#">
<cfdump var="#arguments#">
</cfif><!--- End of Sid's Mod --->