CF Pest Control By Shlomy Gantz President Blue
CF Pest Control By Shlomy Gantz President, Blue. Brick Inc.
Famous Last words • “…if debugging is defined as the art of taking bugs out of a program , programming must be putting them in…” • “. . It’s not a bug, It’s a feature “ Microsoft
Types of bugs • Syntax Error • Run-Time Errors • Logical Errors
Types of bugs - Syntax Errors • Syntax Error Example <CFSET Client. Name = “Shlomy Gantz”> <CFSET URLstr = URLstr & urlendcodedformat(Client. Name)>
Types of bugs - Run-Time Errors • Run-Time Error Example <CFQUERY NAME=“Get. Over. Paid. Emp” Datasource=“Payroll”> SELECT SUM(Salary) AS Total. Salary, COUNT(Emp_ID) as Num. Of. Employees FROM Annual. Salary WHERE SALARY > 100000 </CFQUERY> <CFSET AVGSalary = Get. Over. Paid. Emp. Total. Salary/Get. Over. Paid. Emp. Num. Of. Employees> <CFOUTPUT>#AVGSalary#</CFOUTPUT>
Types of bugs - Logical Errors • Logical Error example <CFSET My. List=“Shlomy, Michael, Emily, Abraham”> <CFSET Shlomy. Exists_YN = listfind(My. List, ”shlomy”)> <CFOUTPUT>#Yes. No. Format(Shlomy. Exists_YN)#</CFOUTPUT>
Other things that can go wrong • • • Database connection (ODBC, MDAC …) Cold Fusion server Web Server OS Hardware
Debugging Steps • • Plan Back-up Isolate Find The error Fix - Don’t patch Look for similar Document
“Debugger’s Block” • If all else fails • … and if that doesn’t work
Cold Fusion Administrator
Cold Fusion Administrator
Enable CFML stack trace • CF tracks what tags have run during page process. • Can be used either through CFTRY/CFCATCH or the Home. Site+ Debugger
Report Execution Times
Show Variables • Show all variables processed by Cold. Fusion: – – – – – Application Cookie Server CGI Form Session Client Request URL
Detail View • Breakdown of all templates run during a page process. • Processing time for each template
Database Activity • • Query Name Record. Count Processing Time Query Executed
Enable Performance Monitoring
Enable Robust Exception Information • • • physical path of template URI of template line number and line snippet SQL statement used (if any) Data source name (if any) Java stack trace
Debugging IP Addresses • By Default All when debugging is turned on all users can see debug information. • You can restrict access to the debugging info through this feature by IP address
Log Files • Easier Log File Administration
Log Files • Easier Log Analysis
System Probes • Monitor your Cold. Fusion Applications
Code Analyzer
Debugging with Home. Site+ • Setting up Development Mapping.
Using the interactive debugger
Debugging CF applications • Show your variables (not only once) • Create breakpoints and Follow the flow • Use Exception handling to automatically alert when errors occur • Look at your application logs • <CFDUMP>
<CFABORT> & <CFOUTPUT> • Using CFABORT to create breakpoints <cfinclude template="Header. cfm"> <cfquery datasource="#dsn#" name="get. Contacts"> Select * from Contacts WHERE Active_YN=1 </cfquery> <cfoutput>#get. Contacts. recordcount#</cfoutput> <cfabort>
<CFABORT> & <CFOUTPUT> • Following the flow <CFIF …………> Step 1 <CFIF ………………. . > Step 1. 1 <CFELSE> Step 1. 2 </CFIF> <CFELSE> Step 2 </CFIF>
Debugging in CFML • <cfquery debug> • <cfstoredproc debug=“yes|no”> • <cfsetting showdebugoutput=“yes/no”>
Debugging CF applications • • • <CFERROR> <CFTHROW> <CFRETHROW> <CFCATCH><CFTRY> <CFLOG> <CFTRACE>
<CFERROR> • <CFERROR TYPE="Request" or "Validation" or "Monitor" or "Exception" TEMPLATE="template_path" MAILTO="email_address" EXCEPTION="exception_type">
<CFTRY><CFCATCH> • <CFTRY> • . . . Add code here • <CFCATCH TYPE="exceptiontype"> • . . . Add exception processing code here </CFCATCH> • . . . Additional CFCATCH blocks go here </CFTRY>
<CFTHROW><CFRETHROW> • <CFTHROW TYPE="exception_type" MESSAGE="message" DETAIL="detail_description" ERRORCODE="error_code" EXTENDEDINFO="additional_information">
<CFLOG> • <cflog type="Error" file="myapp_errors" text="Exception error -- Exception type: #error. type# Template: #error. template#, Remote Address: #error. remote. Address#, HTTP Rerference: #error. HTTPReferer# Diagnositcs: #error. diagnostics#">
<CFTRACE> • <cftrace abort = "Yes or No" category = "string" inline = "Yes or No" text = "string" type = "format" var = "variable_name" >
Is. Debug. Mode() • <cfif Is. Debug. Mode()> <h 3>Debugging is set in the Cold. Fusion Administrator</h 3> <cfelse> <h 3>Debugging is disabled</h 3> </cfif>
Application Logs • Read your application logs regularly Error", "TID=199", "07/27/00", "13: 32: 35", "127. 0. 0. 1", "Mozilla/4. 0 (compatible; MSIE 4. 01; Windows NT)", "An error has occurred. HTTP/1. 0 404 Object Not Found“ "Error", "TID=199", "07/27/00", "13: 32: 45", "127. 0. 0. 1", "Mozilla/4. 0 (compatible; MSIE 4. 01; Windows NT)", "Error resolving parameter SLOT_IDCold. Fusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either: You have misspelled the parameter name, or You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag. The error occurred while evaluating the expression: #slot_id# The error occurred while processing an element with a general identifier of (#slot_id#), occupying document position (4: 12) to (4: 20) in the template file D: wwwrootcfun 2000ExamplesJSJSexample 1_CFMWedit_def. cfm. Thespecific sequence of files included or processed s: D: WWWROOTCFUN 2000EXAMPLESJSJSEXAMPLE 1_CFMWEDIT_DEF. CFM . Date/Time: 07/27/00 13: 32: 45 Browser: Mozilla/4. 0 (compatible; MSIE 4. 01; Windows NT)Remote Address: 127. 0. 0. 1 HTTP Referer: http: //127. 0. 0. 1/cfun 2000/Examples/JS/JSexample 1_CFMW/EDIT. HTMLTemplate: D: wwwrootcfun 2000ExamplesJSJSexample 1_CFMWedit_def. cfm“ "Warning", "TID=152", "07/27/00", "15: 07: 21", "In a CF_Tag. Name construct custom tag file 'C: CFUSIONCustom. TagsPages. cfm' will occlude custom tag file 'C: CFUSIONCustom. Tagscf_pagesPages. cfm'. " "Warning", "TID=152", "07/27/00", "15: 07: 21", "In a CF_Tag. Name construct custom tag file 'C: CFUSIONCustom. TagsPages. cfm' will occlude custom tag file 'C: CFUSIONCustom. Tagscf_pagesimagesPages. cfm'. "
CFDUMP • Read your application logs regularly <CFDUMP VAR="#my. Var#">
Debugging Databases • SQL query analyzer
Common Mistakes “So what are we doing wrong? ”
Tools & Techniques • <CFMAIL> Alerts • Monitoring Tools (http: //www. pingalink. com ) • Testing Tools (http: //www. opendemand. com ) • Bug. Traq • Automatic Code Generation Tools – Code. Saver / Code. Charge / Commerce. Blocks • Lo. RCAT
QA • Shlomy Gantz shlomy@bluebrick. com http: //www. shlomygantz. com
- Slides: 42