5 Replies Latest reply on Aug 18, 2006 5:51 AM by ProphecyVI

    CF throws undefined var, but error email includes it

    ProphecyVI Level 1
      We have a sitewide error handler that emails us whenever an error occurs on a site. This error email includes cfdumps of every scope.

      Frequently I receive error mails telling me that variable X is undefined in Session. So I scroll down the email to the Session scope dump, and... there's the variable. So CF thinks it doesn't exist and throws an error, but it appears in a cfdump of the session scope in the error handler. Any idea what causes this?
        • 1. Re: CF throws undefined var, but error email includes it
          Level 7
          Which version of CF?

          --
          Adam
          • 3. Re: CF throws undefined var, but error email includes it
            A3gis Level 1
            could it be picking up session info from a different user? have you looked at the http_user_agent - is it a human user or a crawler? have noticed wierd things with our error emails and crawlers on occasion.
            • 4. Re: CF throws undefined var, but error email includes it
              Level 7
              I have - in the past - had problems managing session variables with
              constructs like this:

              <cfif isDefined("session.foo")>
              <cfoutput>#session.foo#</cfoutput>
              </cfif>

              Where the isDefined() expression was true, but the following line errored
              with "variable does not exist".

              It was only with session variables that this happenend.

              We changed to using structKeyExists(), and the problem went away. This was
              back in CFMX6x, and have never used isDefined() since, so not sure if the
              problem still persists.

              This does not help your situation, but is perhaps confirmation that there
              is something flaky about the session scope, and how CF determines the
              existence of variables in it.

              I don't know how the error template stuff works... is it a separate request
              (ie: are things like Application.cfm executed again?). Could the variable
              somehow be getting set between the time the error is thrown and when the
              <cfdump> is emailed to you?

              Does the error always crop up at the same piece of code / same variable, or
              could it be any session variable, at various different places in your code?

              --
              Adam
              • 5. Re: CF throws undefined var, but error email includes it
                ProphecyVI Level 1
                @Aegis:
                I've noticed the same. Crawler errors I just ignore.

                @Adam:
                Error occurs at any random point in evaluating session variables. I used to think the sessions were just timing out, but then I set a one-year session timeout and it didn't change anything.

                I'll give the StructKeyExists method a try, see if that helps any.

                As far as the error template, you can specify a file in CF admin to run whenever an unhandled exception occurs. It essentially runs as an include in the template that threw the error. So we have ours show the user a pretty "we're sorry" screen and send us an email with the error & all the scope dumps in it. It doesn't rerun any new code (like app.cfc), it acts something like a dynamically-included file with an abort at the end of it.