Twitter: raymondcamden


Address: Lafayette, LA, USA

Remember this special little rule about ColdFusion Components

04-02-2013 3,639 views ColdFusion 8 Comments

I just spent some time helping a person debug an issue that turned out to be one small little problem. He had a form that posted to a CFM page. On that CFM page he had quite a bit of processing going on, but the result was always the same - a blank white page.

I walked him through my normal debug process. Lots and lots of messages. I know that sounds lame, but I approach templates like this with a top-down process. So for example, imagine the following pseudo-code:

if something
do this
end if

if something
do this
end if

do crap
do some more crap

if something
do this
end if

I'll start putting messages before each portion of the code. Simple stuff like:

"Before first condition." "After second condition." "Before I do crap"

You get the idea. The further I go, the more I cuss. It helps. Honest.

So while working through this process with the guy, we got down to the final code block that caused the abort. In this case, it was a call to a CFC using cfinvoke.

My first thought was something funky with his exception handling. I had him wrap the cfinvoke code with a try/catch/dump, but it didn't report anything.

So I opened up the CFC. The method didn't use a cfabort. Heck, it was a two line query. Very simple.

It was then that I began to scan upwards and saw....

<cfabort>

This wasn't inside a method. It was just sitting there. Sneaky little bastard.

People new to CFC development often forget a very critical rule: Every line of CFML that is not inside a cffunction block will execute whenever you create an instance of a CFC. In this case, the cfabort was in the middle of the file in an easy to miss position, and the user wasn't even aware of this particular feature.

So... yeah. Keep that in mind. :)

8 Comments

  • Commented on 04-02-2013 at 2:15 PM
    @Raymond:

    How come you don't use the step debugger?
  • Commented on 04-02-2013 at 2:56 PM
    I don't care for it. And in this case, I was walking him through it on IM.
  • Commented on 04-02-2013 at 4:06 PM
    Yeah, I've had varying degrees of success with the step debugger. In the end, I've rarely had to step debug through ColdFusion code. Now JavaScript on the other hand - I've started adding "debugger;" at the top of every new function I write and I examine every assumption. ColdFusion just works.
  • Commented on 04-02-2013 at 4:16 PM
    After helping this guy for an hour, I will take issue with "ColdFusion just works." ;)
  • Commented on 04-03-2013 at 3:24 AM
    ColdFusion debugger is just a pain including the setup!
  • Dan Fredericks #
    Commented on 04-03-2013 at 6:12 AM
    The Step/line debugger in eclipse/builder, once setup right (that is a whole other story), really has helped us get through the huge coldbox code mess we have. Before I used the debugger, aborts and cfmail, catch/try was the only way, now with line debugger, it is much easier...but that is of course if I can get it set up...but again, everyone has a different feel for it...I still like to use the Ray approach, messages everywhere till i get what i need...LOL
  • Commented on 04-03-2013 at 6:14 AM
    I can definitely see the debugger being useful in a MVC app. I think last time I used the debugger it was in just such a situation.
  • Jim #
    Commented on 04-09-2013 at 12:09 PM
    I have issues with the debugger as well. I've used it in the past, but for one thing it's painfully slow and hard to set up. Sometimes the mappings seem to work, other times they don't. I have not used it recently.

    We use Coldfusion here since we have limited resources for web applications (i.e. me) and it's still one of the quickest ways to get things up and running but there are some things that are just a pain, the debugger is one.

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty