YOUR FEEDBACK
NGASI Releases AppServer Manager 8.1
Dave Jenkins wrote: The remote server management is a welcomed added feature...
SOA World Conference
Virtualization Conference
$200 Savings Expire May 16, 2008... – Register Today!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP COLDFUSION LINKS


Errors in Your Code
Handling, debugging, and testing for them

Digg This!

Page 2 of 2   « previous page

Debugging: Resolving Errors
When it comes to resolving errors, there are a variety of tags and techniques to assist you. Some are features to help you while running a request to provide additional information to track the program's state, while another is the ability to do interactive step debugging, and the last are related to getting system diagnostics. We don't have room to elaborate on these, but do be aware of them.

Additional Info To Track Program State
The first set of debugging tools, some of which are widely used while others are still a surprise to many, are the debugging info enabled in the Admin console, CFDUMP, CFLOG, CFTRACE, CFTIMER, and the cfstat command-line utility (BlueDragon doesn't currently support the last two). Even CFOUTPUT and CFABORT can be useful techniques when debugging. These topics have been covered in more depth in the following articles (and of course, the documentation):

There is also a new article this month related to the above: "Faster debugging with CFTIMER and CFTRACE", by Shlomy Gantz.

I'd also like to point out that BlueDragon offers a useful tag called CFDEBUGGER to supplement those above. It traces all the lines of CFML code executed in a given request, something that CF developers have never had. I wrote about it in a past CFDJ article: CFDEBUGGER (November 2003) http://coldfusion.sys-con.com/read/42101.htm.

Interactive Step Debugging
Of course, when some think of debugging they immediately think of interactive "step" debugging, and those folks have long complained that CFML lacked such a capability (while some others don't miss it at all). As we went to press, the folks at Fusion-Reactor.com (Intergral GMBC) released their FusionDebug tool, which is an Eclipse plug-in that finally provides step debugging for ColdFusion MX. Learn more at www.fusion-reactor.com/fusiondebug. It's something I'm excited about. While many never knew it, we did indeed have debugging available in ColdFusion 5 and before by way of ColdFusion Studio (or today's HomeSite+). I've mentioned it in, "Browsing within CF Studio/HomeSite+" (August 2003) http://coldfusion.sys-con.com/read/42061.htm. I even walked folks through using it in a 1999 presentation, available at www.systemanage.com/presentations/debugger-setup.pdf. One reason I never wrote about it here is that it didn't always work. Still, I'll point out that the official documentation, which many never knew existed, was in Chapter 9 of Using ColdFusion 5 Studio at http://livedocs.macromedia.com/coldfusion/5.0/Using_ColdFusion_Studio/debug.htm. It should be possible to get it working with CF Studio and/or HomeSite+ with ColdFusion 5, if you still have them both.

System Diagnostics
Of course, sometimes to understand error situations you need more information than just what's reflected in running the current page. There could be other activities or problems in the environment that are impacting your code. When it comes to gathering diagnostics to understand and resolve problems, you should consider taking advantage of the built-in logs, available in the aforementioned ColdFusion logs directory. There's also an interface to view them in the Admin console.

Beyond that, though, there's even more powerful analysis of what's going on in your environment available by way of two commercial (yet reasonably priced) tools that have come out in the past year or so: SeeFusion at www.seefusion.com and FusionReactor at www.fusion-reactor.com. Both are available on a free trial basis so check them out.

There may be problems that are outside of ColdFusion that are affecting you. Be sure to consider analyzing your Web server, database, network, and the operating environment of the machine running ColdFusion. There are logs and analysis tools for each that are beyond the scope of this article. Finally, another vital tool when solving problems in CFML is simply knowing what you should and shouldn't be doing in CFML. Don't forget that you have documentation available at livedocs.macromedia.com (no, the domain name hasn't changed yet). And more than just the CFML reference, there's a 900+ page Developer Guide and more.

Testing: Preventing Errors in the First Place
While it's admirable to do a better job catching, handling, and debugging errors when they occur, shouldn't we try to prevent them in the first place? There are several ways you may be able to test your code to prevent errors occurring at all, as we will discuss, ranging from unit testing to syntax checking to validating your page input and output.

Unit Testing
To prevent bad code from getting into production many would recommend doing better unit testing, a subject within the broader topic of test-driven development. CFML offers various implementations of such unit-testing tools ranging from test harnesses to cfunit and cfcunit, as discussed in:

Note that cfunit used to be part of the Developer Resource Kit (DRK) but it's now available at the site above. There are still other forms of testing to keep in mind.

CFML Syntax Checking
Since CFML isn/t a compiled language, many errors slip by because we don't need to "run a compile step" before releasing our code into the wild. We may have syntax errors that would cause a page to fail as soon as it's run. How can we catch them without actually running every page? Again, good unit tests would help, but until you implement them, there's still another approach.

Did you know that there are various means to check your CFML code's syntax before releasing it? Since release 4, the Admin console has had a mechanism that lets you point to a directory of code. It will analyze your CFML and report if there are problems. While in CFMX it's formally called a Code Compatibility Analyzer, with a focus on checking code from previous releases, it also does CFML syntax checking (see the "Advanced Options"). There has also been one in CF 4 and 5. Note that you can point it at an entire directory (and optionally recurse into subdirectories), so it's definitely something to consider as a regular part of testing. See the online help in the Admin console for more information.

Perhaps you're perturbed that that tool is a Web interface requiring you to enter data in a form. You want a command-line tool. I'm not aware of a means to call that compatibility analyzer from the command line, but did you know that CFMX 6.1 added a command-line precompile tool? It's in the /bin directory as cfcompile.bat. While the primary purpose is performance improvement (saving the auto-compile that takes place on first load of the page into server memory), it will report if there are any errors during evaluation of the CFML, so it can act very much like the missing compilation step that other developers use to catch errors early. Again, it is a command-line tool, and it does by default compile all templates in a given directory.

See Chapter 5 of the CFMX 7 Administration manual (but not in the CFMX 6.1 manual) for more information. It's also discussed in the following article. Though the focus is on J2EE Web application deployment, the discussions of cfcompile are still broadly useful: "Deploying Applications with ColdFusion MX 7" (Dave Carabetta, March 2005) http://coldfusion.sys-con.com/read/48654.htm.

I'd like to point out also that I had discussed the benefits of such a precompile tool in a two-part series. Though it was written before the tool was released officially in 6.1, some of the info may still benefit:

Input and Security Validation
Still another form of testing to consider before you turn your application out for production implementation is a range of tests that focus on ensuring that the application avoids errors by preventing inappropriate input or cross-site scripting as discussed in: Output Validation
Other forms of testing focus on the output of your pages such as validating your HTML code (accessibility checking, CSS validation, link checking, and spell checking) as well as regression, load, and concurrency testing. I covered all of these in "E-Testing: Debugging Your Projects" (October 2001) http://coldfusion.sys-con.com/read/41816.htm.

Other Error-Related Topics
There are still other topics that are tangentially (or perhaps directly) related to error handling, including handling errors from CFMAIL, using the CFTHROW tag, doing site monitoring, load testing, and leveraging version control to manage your code better and recover from erroneous code releases. Again, there's no room to elaborate, but I'll point out one more article that covers a range of topics including error handling, testing, and source control: "7 Habits of Highly Effective ColdFusion Developers" (Robi Sen, February 2004) http://coldfusion.sys-con.com/read/43534.htm.

And while I'm mentioning error-handling articles, some will get value out of a past article on handling errors in JavaScript: "Error Handling in JavaScript" (Steve Bryan, October 2002) http://coldfusion.sys-con.com/read/41671.htm.

Finally, I'll also point out that in this month's issue there is an article from Joshua Curtiss on yet another error-handling concept, "Handling 404 Errors for a Migrated Blog".

I hope this trip through the archives of the CFDJ focusing on error handling, debugging, and testing will help improve the quality of your CFML development.


Page 2 of 2   « previous page

About Charlie Arehart
A veteran ColdFusion developer since 1997, Charlie Arehart is a long-time contributor to the community and a recognized Adobe Community Expert. He's a certified Advanced CF Developer and Instructor for CF 4/5/6/7 and served as tech editor of CFDJ until 2003. Now an independent contractor (carehart.org) living in Alpharetta, GA, Charlie provides high-level troubleshooting/tuning assistance and training/mentoring for CF teams. He helps run the Online ColdFusion Meetup (coldfusionmeetup.com, an online CF user group), is a contributor to the CF8 WACK books by Ben Forta, and is frequently invited to speak at developer conferences and user groups worldwide.

CFDJ LATEST STORIES . . .
AJAX World - Sun Talks Up its Late-to-the-Party AIR-Silverlight Rival
At Java One this week Sun has been selling its year -old-but-still-upcoming - and definitely late-to-the-party - Adobe AIR- and Microsoft Silverlight-competitive JavaFX Rich Client environment as a potential revenue-generator capable of putting ads on mobile applications and JavaFX Scri
AJAX World - Xceed Launches Microsoft Silverlight 2 Control
Xceed launched Xceed Upload for Silverlight, the commercial offering in support of Microsoft's promising new Silverlight technology. The product is available now for purchase or as a fully functional 45-day trial on Xceed's website. Xceed Upload for Silverlight lets developers add uplo
Microsoft To Keynote 4th International Virtualization Conference & Expo
Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
Red Hat is a trusted open source provider. Red Hat offers enterprise customers a long-term plan for building infrastructures on the quality and innovation of open source. Combining open source operating system platform, Red Hat Enterprise Linux, together with applications, management
Building an IM Bot Using ColdFusion
I recently brought a Google Talk bot that I put online at cfdocs@gmail.com. Google Talk users can add this user to their buddy list and then submit CFML tag and function lookups to it. (I've also brought Yahoo IM and AIM versions online as nickname cflivedocs, but more on those shortly
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE