NetTalk Central

Author Topic: Checking Session Values are present in debug mode  (Read 7272 times)

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Checking Session Values are present in debug mode
« on: August 03, 2010, 09:37:31 AM »
Session values take the place of variables extensively, but unlike variables the compiler will cheerfully accept any typo'd or missing session value.  You can go quite a while without noticing the problem.

For those situations where the session value must be present, I use a new method, GSV2, that simply calls GSV for the session value and ASSERTS that the returned string is not empty before returning the session value.  If it is empty, the ASSERT message identifies the called session value as missing.  Since ASSERT only fires in debug mode, it never interupts server operation in release mode.

I add this method to the base class because of the complexity of adding the method to a derived base class.  The protype is:
GSV2                   PROCEDURE(String p_Name),STRING,VIRTUAL

The method code is:
NetWebServerWorker.GSV2  PROCEDURE(STRING p_Name)     
GSV2String   STRING(256)
  CODE
   GSV2String = self.GSV(p_Name)
   ASSERT(CLIP(GSV2String) ~= '','Session Value empty: '&CLIP(p_Name))
   RETURN CLIP(GSV2String)

While I don't like making changes to the base class, at least the compiler will let you know if you have updated the base class without adding the this method.
   
This method has saved me a lot of time, so I am passing it along.  If there is a problem with it, please post your concerns.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: Checking Session Values are present in debug mode
« Reply #1 on: August 04, 2010, 05:40:16 AM »
Hi Casey,

I guess the problem here is two-fold;
a) it's legal to get a session value with an empty string in it and
b) it's legal to "get" a session value that hasn't been added yet.

your technique is good, however you're likely to get false positives (ie asserts popping up when they shouldn't) and also of course it doesn't catch any case where the SSV is the method at fault.

I understand your main concern though - I just don't see a practical, complete solution.

Incidentally, there is a IfExistsSessionValue method you can use to overcome issue (a) - but that still leaves problem (b) unsolved.

cheers
Bruce

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Re: Checking Session Values are present in debug mode
« Reply #2 on: August 04, 2010, 07:46:44 AM »
Hi, Bruce

The intent wasn't to replace the use of GSV,  for all the reasons you mentioned. Just in those situations where the session value has to be there for the program to work properly.  Limiting it to those situations should eliminate false positives.  I haven't had one yet, but if I applied GSV2 to the wrong session value and got one I would just change it back to GSV,

Thanks for the comments.