-6

For example, I have a page. I can load this page 100 times without error. However sometimes someone gets an error because I get the email that is sent from ColdFusion in the onError method. I don't get them a lot, but I get them more than I would think I should. It's impossible to "debug" because it doesn't happen all the time. Once a day maybe on a given page.

Has anyone seen anything similar.

One exmaple:

if((StructKeyExists(ARGUMENTS.itm, 'video_code') && len(trim(ARGUMENTS.itm.video_code)) || !StructKeyExists(ARGUMENTS.itm, 'video_code')) == 0) return '<a #class# #target# #linkid# #pageid# href="#url#">#title##fileext#</a>';
    else return '<a class="youtube_video" #target# #linkid# href="http://www.youtube.com/v/#itm.video_code#?version=3&autoplay=1&rel=0&modestbranding=1">#title#</a>';

In this page request, the item struct had video_code in there. But when the second line was processed video_code was undefined. I can run the page 100 more times, and this doesn't happen.

objectType  class coldfusion.runtime.Struct
element VIDEO_CODE
Resolvedname    ITM
Detail  
ErrNumber   0
Message Element VIDEO_CODE is undefined in ITM.
Type    Expression
Trace:  Template    Line
D:\www\websites\assets\cfcs\menu.cfc    240
D:\www\websites\assets\cfcs\menu.cfc    209
D:\www\websites\assets\cfcs\menu.cfc    15
D:\www\websites\assets\templates\distance_general\campus_index_page.cfm 120
D:\www\websites\domain.com\index.cfm    1
11
  • 3
    You need to post code for someone to be able to help you, not just say "it errors". If you go in with the attitude that it's impossible to debug, then it will be Jan 15, 2013 at 16:44
  • There is nothing to post. I am not asking a specific question about a specific line of code. The code in question where the error happens is simply on this specific page load. The other 1000 page loads it's fine. It's a conditional statement based on a SQL query. However I get similar things on other pages in other lines of code. Ramdon errors, that don't happen when I visit the page. Nothing based on SESSION or anything like that.
    – Leeish
    Jan 15, 2013 at 16:46
  • What is the error message you get? Jan 15, 2013 at 16:46
  • Fine, I'll post the code, but this is just one instance. There are other seemingly random ones.
    – Leeish
    Jan 15, 2013 at 16:48
  • 3
    These things are always possible to debug. Try/catch the erroring line of code and write all the variables contributing the logic out to a log file, to verify they all have the values you expect. This would have solved this issue because you'd've spotted that a combination of events you (and your logic) wasn't expecting. This would have lead you to fix the logic, and the problem would go away. Jan 15, 2013 at 18:59

2 Answers 2

5

It's a bug in your code.

That's the standard automatic response when anyone asks a question like the one you have, because it's almost always the case.

There is of course a chance that you've identified a flaw in ColdFusion, but the odds of finding a bug in an established product are significantly lower than those of it being an error in your specific code/config.

Given the convoluted code provided as an example, the probably is very high that it's a bug in your code.

can programming languages mis-parse at times or anything like that.

Simply, no. There are no parse-level constructs that would make the parser behave differently, and the parsing is done once, then the same compiled code is used (until cleared or server restarted).

why this would not fail 100 times over and fail once?

Looking again at the example, it may well be a scoping issue - you are checking StructKeyExists on ARGUMENTS.itm but are then using simply itm in the code. ColdFusion has threading issues with unscoped variables that can manifest when under heavy load.

Use varscoper to check for unscoped variables.

16
  • I suspect it has to do with operator precedence. !expression == 0 is parsed as !(expression == 0), not (!expression) == 0.
    – Barmar
    Jan 15, 2013 at 17:48
  • I am not doubting there is bugs in the code I work with. It's been written over the past three years with various programmers. I am asking a general question... can programming languages mis-parse at times or anything like that. I dobut it, but worth asking. It's strage a page cna be processed 100 times over, but once in a while throw an error when nothing changes. Why would it only happen... every once in a while?
    – Leeish
    Jan 15, 2013 at 17:49
  • 1
    One of our programmers loved double negatives and ternary operators which makes the code wonderful to sift through.
    – Leeish
    Jan 15, 2013 at 17:51
  • 1
    Ahhh... Now that makes some sense. We have more of these after a server/application restart and certain times of the year when we are under heavy load.
    – Leeish
    Jan 15, 2013 at 18:02
  • 1
    That answers my original question. I wasn't trying to be an ass or lazy and not show code. I know there are potential bugs, but knowing how a lot of our code looks, and how bad unscoped variables can be, that puts more importance on unscoped variables. Thanks for your help.
    – Leeish
    Jan 15, 2013 at 18:09
2

It's an actual bug in your code. The if condition is:

(StructKeyExists(ARGUMENTS.itm, 'video_code') && len(trim(ARGUMENTS.itm.video_code)) || !StructKeyExists(ARGUMENTS.itm, 'video_code')) == 0

which means that the else condition is:

(StructKeyExists(ARGUMENTS.itm, 'video_code') && len(trim(ARGUMENTS.itm.video_code)) || !StructKeyExists(ARGUMENTS.itm, 'video_code'))

So the else clause will be executed when ARGUMENTS.itm.video_code exists and is not empty, or when it doesn't exist. In the latter case, the reference to itm.video_code on the second line will fail.

I can't explain why the error happens intermittently. I think you need to look at the different callers, to see why the argument sometimes doesn't exist.

3
  • I can verify what @Barmar says. As to why it happens intermittently? I presume that the occasions that arguments.itm exists but arguments.itm.video_code doesn't exist occur only intermittently. The conditional logic you have there is awful to decipher btw. You should revise that if poss. A case in point if the logic was clearler, the logic error would have been easier to spot. Jan 15, 2013 at 18:51
  • I had to apply de Morgan's theorem about 4 times to simplify it.
    – Barmar
    Jan 15, 2013 at 19:22
  • 1
    My head hurts after reading that. I dunno why the logic ain't just if(it exists and it has length) {do it} else {don't do it}. Isn't that what it amounts to (or at least SHOULD amount to)? Jan 15, 2013 at 20:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.