YOUR FEEDBACK
ASP.NET
mark bosley wrote: Good article. Please post the code or send it to me. It ...
AJAXWorld RIA Conference
$300 Savings Expire July 25
Register Today and SAVE!


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


CFDJ Feature - How to Debug Your ColdFusion Applications
Problem solving and techniques for your debugging adventures

Digg This!

Page 1 of 2   next page »

I just spent four hours debugging an error for a client. The client is an application service provider, and they developed an administrator for internal use. The administrator allows for the user to switch between sites, at whim. The "site switcher" is a drop menu, which loads up a different DNS depending on the selected site.

A certain set of code was working for all sites except one. The application was not throwing errors, but nothing was getting displayed on the page. How do you find the problem? I'm going to step you through the process I took to solve the problem, and along the way, I hope you'll learn a technique or two that you can use in your own debugging adventures.

Two Types of Errors
There are really two types of errors that you'll encounter in your code: syntax errors and logic errors. Syntax errors are those ugly ColdFusion errors that you are used to seeing every day as you write code (I know I'm used to seeing them). Generally these are easy to discover and address. These are usually squashed during your development.

The most common reason why I see syntax errors on production sites is due to undefined variables being accessed. Sometimes there is some link somewhere that is missing a URL variable, or perhaps someone changed the Query String and reloaded a page. Sometimes a checkbox form element is accessed, yet the user did not check anything before submitting the form, so it is undefined or a shared scope variable may be accessed before it is set. Other reasons that ColdFusion might throw syntax errors might be invalid tags or attributes, mismatched tags, or database timeout.

Syntax errors are easier to find than logic errors. Logic errors occur when the code that you've written doesn't satisfy the business requirements you were setting out to implement. Some business requirements might be easy to fix, such as display 20 products per page instead of 15. Others might become murky to catch, such as people who buy at least five products from Product Line A get a 10 percent discount on all products from Product Line A in their order, unless they have three products of Product Line B attached to the same order, whereas they receive the bigger discount of 10 percent off Product Line A products or 5 percent off of all Product Line B products. The best way to avoid business logic errors like these is to have a clear set of business requirements before you start to code the application. Sometimes it's hard for the client to see the big picture.

Examining the Debugging Output
Going back to my problem of the day, I started out by assuming that the code was fine, since it was working for all of the sites except one. The problem must reside in the data. The page in question was supposed to show a list programs from the database. If no programs existed, then a blank display is not a surprise. I tracked down the query code and executed it manually against the database using Query Analyzer (an SQL Server tool). The query worked fine and the proper data was returned. This query didn't contain any CF variables, so the cause of this couldn't have been invalid values.

Just to be sure, I wanted to review the SQL actually being sent to the DB. For this I needed to turn on ColdFusion's debugging output. In normal cases, you wouldn't turn on debugging for a production site, but I decided this case was an exception. The site only has half a dozen users, none of whom could use the site until the error was fixed. You can turn on debugging from your ColdFusion Administrator using these instructions:

1.  Go to your administrator. Most likely the URL is www.yoursite.com/cfide/administrator. You'll see a screen similar to Figure 1. It might look a little different for those who have already upgraded to CF7. Enter your password to login.

2.  Under Debugging and Logging select Debugging Settings. You'll see the different things that can be displayed in debugging output, as shown in Figure 2.

3.  Check the Enable Debugging box, if not already done. I also like to click the Enable Robust Exception Information so that I can view the full SQL statement, and other information about the queries that run.

4.  While you're in here, take some time to examine the list of other information that can be displayed in the debugging output. You can select the type of display, either dockable or classic. I prefer classic, the default method. You can also display various variable scopes, tracing information (used in conjunction with the cftrace tag), exception information, database activity, and general debug information. Most commonly I use the variables and database activity.

Back to the problem at hand: I enabled debugging and reran the template. I scrolled down and looked for the debugging output. The query I was looking for was not executed. Why was that?

cfdump and cfabort
The template in question is what I call a "case" template. Based on some mode variable, different code is executed within the template, often with completely different execution and results. I call it a case template because a different cfcase statement represents each mode. All of this inside the cfswitch tag. For more information, see: http://livedocs.macromedia.com/coldfusion/7/ htmldocs/00000339.htm#1103819. This type of template is very similar to a fusebox approach to designing Web applications. The mode would be a "fuseaction" and the base template would be the "fusebox" template. I know by looking at the URL that a client-side redirect is not happening, which leaves two options. Either the wrong "mode" is being executed or a server side redirect is happening.

The first thing I wanted to do was to verify that the mode was correct. I turn to cfdump tag for that. cfdump is a very useful debugging tag that displays the contents of a variable. With simple variables, you could use a cfoutput to display the value of that variable, however for complex variables such as an array, structure, or XML document the cfdump is invaluable. cfdump has a few attributes, but the one we care about for the moment is the var attribute. You use the var attribute to specify which variable you want to display. Always make sure to enclose the variable name in pound signs, or else the variable name will be displayed instead of the variable value. You can check out the full documentation on cfdump at http://livedocs.macromedia.com/coldfusion/7/ htmldocs/00000239.htm#3765824.

I used cfdump to dump the value of the mode variable before entering the cfswitch tag. The code looked something like this:

<!--- code here --->
<cfdump var="#mode#">

<cfswitch expression="#mode#">
<!--- more code here --->


Page 1 of 2   next page »

About Jeffry Houser
Jeffry Houser has been working with computers for over 20 years and in Web development for over 8 years. He owns a consulting company and has authored three separate books on ColdFusion, most recently ColdFusion MX: The Complete Reference (McGraw-Hill Osborne Media).

CFDJ News Desk wrote: CFDJ Feature - How to Debug Your ColdFusion Applications. I just spent four hours debugging an error for a client. The client is an application service provider, and they developed an administrator for internal use. The administrator allows for the user to switch between sites, at whim. The 'site switcher' is a drop menu, which loads up a different DNS depending on the selected site.
read & respond »
CFDJ LATEST STORIES . . .
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be
Voyager Offers Android, .NET CF, Java Runtime Support
Recursion Software released a private beta version of their Voyager mobile platform, with powerful interoperability for Android, Microsoft .NET and Compact Framework (CF), all Java editions (JME CDC, JSE and JEE), and more than 15 embedded operating systems. The Voyager platform is a p
AJAX and Enterprise RIA Tools - JSF, Flex, and JavaFX
2008 is going to be an important year for Rich Internet Applications. Most organizations are delivering or planning to deliver Rich Internet Applications; however, at the same time, most IT managers are facing a dilemma: which Rich Internet Application technology and platform to use? T
CFDynamics Announces Renewed Agreement with SmarterTools
CFDynamics, a ColdFusion web host, has renewed an agreement with SmarterTools that will allow them to pass on immediate value to their customers. When a customers signs up for a dedicated hosting account they will now receive $750 worth of features including SmarterMail, SmarterStats a
Microsoft's Virtualization Chief Mike Neil To Keynote SYS-CON's 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
SYS-CON's 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
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