19.0 Must Be Within Range: ( 1 : 12 )

Posted July 30, 2007 at 5:18 PM

Tags: ColdFusion

I was just helping someone debug a strange ColdFusion error:

19.0 Must Be Within Range: ( 1 : 12 ). ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.

Because ColdFusion wasn't giving us any template or line numbers, we basically had to start commenting out code and putting it back in until we narrowed down the template and the line. And, seeing as I was not working on the project, this was particularly necessary (as I was not familiar with the code at all - just called over for the error). Finally, we narrowed it down to the ColdFusion method, MonthAsString(). This takes a month index and returns the name of the month. Therefore, running:

 Launch code in new window » Download code as text file »

  • #MonthAsString( 1 )#

... gives us:

January

The values, obviously, can only be 1 - 12, as there are only 12 months in the year. As it turns out, there was some weird math algorithm that was passing a variable of the value 19 to the MonthAsString() function; hence the whole out of range error.

Good to know if I ever see this error again.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Jul 31, 2007 at 12:49 AM // reply »
1 Comments

When I was a kid I ran across a few page insert in a day planner that had a system to calculate the day of week (Monday, Thursday, etc.) of any date between around 1500 and 2100. Years later I realized it was based on an algorithm that works for our current calendar system(Gregorian).

I suspect the 19 is a remnant of the formula. The days of week fall on a fairly predictable basis for hundreds of years based on a relatively easy formula.

http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
http://www.jimloy.com/math/day-week.htm


Nic
Aug 3, 2007 at 12:41 PM // reply »
1 Comments

Cool


Nov 3, 2009 at 2:43 PM // reply »
9 Comments

I recently had a similar ColdFusion error with no line number information to help:
11.0 must be within range: ( 1 : 7 )

The date in my Form variable was "11/11/2009" and I was doing this:
DayOfWeekAsString(Day(Form.menu_dt)

After finding this blog entry, I quickly discovered I was out of the range for days in a week and fixed the inner function call:
DayOfWeekAsString(DayOfWeek(Form.menu_dt)


Nov 3, 2009 at 2:57 PM // reply »
6,515 Comments

@Troy,

Yeah, that'll get you ever time :) Good catch.


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 20, 2009 at 5:38 PM
Learning ColdFusion 8: CFImage Part I - Reading And Writing Images
Hi Ben, Great article. I've been looking around to see if ColdFusion image engine can programatically create the following "wrap around" effect: http://www.creativepro.com/article/photoshop-s-she ... read »
Nov 20, 2009 at 5:35 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Dave: I talked to Gert he suggested: <cfhttp method="get" url="http://{some cf website}" result="stuff" addtoken="yes" /> Note the addition of cfhttp attribute addtoken. That should persist y ... read »
Nov 20, 2009 at 5:23 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Todd, Ahh, gotcha, yeah that makes sense. ... read »
Nov 20, 2009 at 5:17 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
Ben, sorry if I didn't make this clear. You can make it work like that if you want, just put <cfset session.foo = 1> (and <cfset application.foo = 1>) in your OnRequestStart() and it reve ... read »
Nov 20, 2009 at 5:07 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Todd, I have seen tidbits about the way Railo handles session. I can understand that it lazy-loads sessions, but I also think that I might make some things more complicated. For example, often tim ... read »
Nov 20, 2009 at 4:53 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
Ben, you can ramp up the security by turning on J2EE session which gives you a third set of numbers other than CFID/CFTOKEN. There's a reason why ACF put this in place (other than just session replic ... read »
Nov 20, 2009 at 4:52 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
Case in point, Ben, you may not be aware of this, but in Railo - OnApplicationStart() & OnSessionStart() act differently than in ACF. ACF does: OnApplicationStart (1st hit) OnSessionStart (1st and e ... read »
Nov 20, 2009 at 4:46 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Todd, That's understandable. I am not sure if this really leaves any more security holes than the fact that using old cookie-based CFID / CFTOKEN values will create a new session using the old CFI ... read »