Skip to main content
Inspiring
May 4, 2016
Question

Coldfusion errors with undefined element, dump during error processing shows element defined

  • May 4, 2016
  • 4 replies
  • 8160 views

Ok, so I've got a strange problem that I've been beating my head against for over a week now.  I'm holding out a little hope that maybe someone here has seen something like this and has a solution or at least can point me in a direction to make some sense of it.


We are running an enterprise application on CF9 currently.  Recently we made a large update with some advancements and in part of the advancements I'm using some request scoped variables.

Said request variable is a structure that is set in Application.cfc OnRequestStart.  Randomly since the changes have been put on our production servers we get an error email (we have an error handler defined to capture and email errors when they occur), stating that key.subkey is undefined in request scoped variable.  What makes this so bizarre is in the email from the error handler (that is processed in the same request) shows the key.subkey existing in the request scoped variable in a <cfdump var="#request#"> in the email.  How could it possibly be erroring on a part of the page that runs after OnRequestStart, but before OnError, saying that this structure element doesn't exist yet it does exist during the error handler caused by it.  The request scoped variable btw is not defined or set anywhere else outside of the Application.cfc.

I should also mention that other keys in the structure are referenced in the request prior to the point of failure without erroring, some in the same function as the point of error even.  It's almost as if the structure is not fully defined yet while it's processing the page request, but it is fully defined by the time it dumps it in the error email....

This problem is really baffling me, and it makes it worse that I can't find any way to reproduce it on our testing servers.

    This topic has been closed for replies.

    4 replies

    BKBK
    Community Expert
    Community Expert
    May 5, 2016

    Steven6282 wrote:

    What makes this so bizarre is in the email from the error handler (that is processed in the same request) shows the key.subkey existing in the request scoped variable in a <cfdump var="#request#"> in the email. How could it possibly be erroring on a part of the page that runs after OnRequestStart, but before OnError, saying that this structure element doesn't exist yet it does exist during the error handler caused by it.

    Your application might inadvertently be triggering an additional request. Although the variable is read in onRequestStart the error occurs where Coldfusion writes the variable.

    To get information about where that happens, replace the dump of the request scope (in onError) with:

    <cfdump var="#arguments.exception#">

    Carl Von Stetten
    Legend
    May 4, 2016

    Also, a screenshot of the <cfdump> (with any sensitive information redacted/blurred) would be helpful.

    Inspiring
    May 4, 2016

    The keys are not empty. They usually have numbers in them in the dumped data.  It depends on exactly which spot the error randomly happens in as to what data is in the struct.  Occasionally there is one with an empty string, but I have verified that it is an empty string, not an undefined value.

    No, sorry I should have been more specific and said I can't even reproduce it on the production server personally.  I've tried doing a lot of different things thinking maybe our users were doing something really weird to cause it to happen, but no matter how many times I refresh or try to load the page a different way I can't find a way to reproduce it.  We have over 4000 users on the production server and over 20,000 requests to the pages that can generate the error per day.  But the error only happens maybe 50 to 100 times a day, so it's a rare hard to reproduce error and obviously doesn't happen every single request.

    Unfortunately I can't practically screenshot any of the data and share it on the internet.  This is a health record application so I would have to redact nearly everything in the dump to share a screenshot without violating HIPAA laws.

    I can give you a little more details on the structure with dummy data though.  Essentially the point of this request scoped variable is to load in client data that is being used across multiple files in the request.  So for example one spot that it commonly errors on the structure it says is undefined is

    Request.Client.Admission.CSMG (csmg being case manager in this case, and is always a number, a client cannot have an admission without having an assigned case manager in the system).

    In the dump it will show Request -> Client -> Admission -> CSMG: 9999, but the point of error says it's not defined.  And two lines of code before the point of error there is a reference to Request.Client.Admission.ADMNO (admission number), that works fine without erroring.

    I tried adding a <cflock scope="session" around the <cfset request.Client = ... > tag today just to be sure, and it did not make a difference.

    EddieLotter
    Inspiring
    May 4, 2016

    Have you reviewed all the ColdFusion log files? It's possible that they might contain a clue as to what might be happening.

    I know it is a production server, but since you're experiencing the error anyway, I recommend you try to access the key immediately after assigning a value to it. That way, when the problem occurs, it will be informative to note where it happens. If it doesn't happen immediately after the assignment then it will be a matter of figuring out what is happening to the key between the assignment and when you access it later in your application.

    Cheers

    Eddie

    EddieLotter
    Inspiring
    May 4, 2016

    Steven6282 wrote:

    This problem is really baffling me, and it makes it worse that I can't find any way to reproduce it on our testing servers.

    Can you reproduce it in a separate test application on the production server?

    Cheers

    Eddie

    Carl Von Stetten
    Legend
    May 4, 2016

    Is the request.key.subkey variable perhaps empty (undefined, null)?  That will result in the struct key showing in a dump but not be able to be referenced.  You might have to wrap that code in a <cfif StructKeyExists( request.key, "subkey" )> to check.