| By Charlie Arehart | Article Rating: |
|
| October 8, 2006 12:00 PM EDT | Reads: |
16,985 |
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):
- "Debugging: Tips and Tricks for Detecting Errors" (Kevin Schmidt, October 2001) http://coldfusion.sys-con.com/read/41827.htm
- "Defending Socrates" (Hal Helms, October 2001)
- "A More Thorough Debugging" (Eric Brancaccio, April 2002) http://coldfusion.sys-con.com/read/41737.htm
- "Macromedia ColdFusion Debugging - Don't Forget Your Bug Spray!" (Nik Molnar, September 2005) http://coldfusion.sys-con.com/read/122162.htm
- "How to Debug Your ColdFusion Applications" (Jeff Houser, October 2005) http://coldfusion.sys-con.com/read/122135.htm
- "Debugging ColdFusion MX7" (Jason Heaslet, October 2005) http://coldfusion.sys-con.com/read/138977.htm
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:
- "Tipping Points: Little Things That Make a Big Difference" (Hal Helms, May 2000) http://coldfusion.sys-con.com/read/41938.htm
- "Testing for Smarties" (Hal Helms, June 2003) http://coldfusion.sys-con.com/read/41899.htm
- "ColdFusion Unit Testing Framework" (Harry Klein, September 2004) http://coldfusion.sys-con.com/read/46361.htm
- "Extreme Programming" (Hal Helms, October 2004) http://coldfusion.sys-con.com/read/46792.htm
- http://cfunit.sourceforge.net/
- http://www.cfcunit.org/cfcunit/
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:
- "Compilation and Precompilation in CFMX Templates--Part 1" (Oct 2002) http://coldfusion.sys-con.com/read/41672.htm
- "Precompiling CFML Templates in CFMX--Part 2" (Nov 2002) http://coldfusion.sys-con.com/read/41684.htm
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:
- "Safe Scripting" (James A. Brannan, June 2000) http://coldfusion.sys-con.com/read/41943.htm
- "Untrusted Data Sources" (Jackson Moore, October 2001) http://coldfusion.sys-con.com/read/41818.htm
- "ColdFusion Security Best Practices" (Bryan Murphy, September 2004) http://coldfusion.sys-con.com/read/46358.htm
- "Top 10 Web Security Tips" (Michael Smith, September 2004) http://coldfusion.sys-con.com/read/46366.htm
- "Strip Tease" (Isaac Dealey, April 2006) http://coldfusion.sys-con.com/read/206288.htm
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.
Published October 8, 2006 Reads 16,985
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By 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.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Adobe Betas Target RIAs and Cloud Computing
- Adobe MAX 2009 Online
- Thinking of Flex in London
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe & Salesforce Cut Cloud Deal
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Is Microsoft as Free as Open Source?
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- Adobe Flex Developer Earns $100K in New York City
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF





































