|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS CF101
CFDJ Feature - How to Debug Your ColdFusion Applications
Problem solving and techniques for your debugging adventures
By: Jeffry Houser
Oct. 21, 2005 09:15 PM
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.
Two Types of Errors 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 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 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 ---> Page 1 of 2 next page »
CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||