I Am So Idiot

Today I found myself chasing my tail for a bit. This function threw an exception at runtime, which indicates that the argument passed in does not match the designated cfargument type. I spent a half hour finding different ways to verify that both inputs, Group_ID and Max_Allowed, were indeed of type Numeric.

The function:

<cffunction name="restrictActiveUsers" output="false" access="public" returntype="Boolean">
   <cfargument name="Group_ID"      required="yes"   type="Numeric" />
   <cfargument name="Max_Allowed"   required="yes"   type="Numeric "/>

   <!--- If there are too many users, get rid of some --->
   <cfif countActiveUsers(ARGUMENTS.Group_ID) gt ARGUMENTS.Max_Allowed>
      <!--- Get the top users. In practice, this is sorted on some criteria. --->
      <cfquery datasource="#Application.Datasource#" name="topUsers" maxrows="#Max(ARGUMENTS.Max_Allowed, 1)#">
         SELECT      u.User_ID
            FROM   tbl_Users u
            WHERE   u.Group_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#ARGUMENTS.Group_ID#">
      <!--- Delete records for users not in the top set --->
      <cfquery datasource="#Application.dsname#" name="deleteBottomUsers">
         DELETE      tbl_Users
            WHERE   Group_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#ARGUMENTS.Group_ID#">
                  User_ID NOT IN (<cfqueryparam cfsqltype="cf_sql_numeric" value="#ValueList(topUsers.User_ID)#" list="yes">)
      <!--- Records deleted, return true --->
      <cfreturn true>
      <!--- Do nothing, return false --->
      <cfreturn false>


The exception (edited for readability, relevance, and to protect the innocent):

CFCATCH.Type: Numeric

CFCATCH.Message: The argument MAX_ALLOWED passed to function restrictActiveUsers() is not of type Numeric .

CFCATCH.Detail: If the component name is specified as a type of this argument, the reason for this error might be that a definition file for such component cannot be found or is not accessible.

So something strange is afoot. Upon further review, I realized that the cfargument for Max_Allowed shows type="Numeric ". Notice the extra space, which means ColdFusion is faihfully validating the type as Numeric-SPACE. This is an invalid data type, hence the exception.

Just goes to show how a fat-finger can throw you for a loop.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner