Modifying Exception Templates in CFMX 7.0.1

A while ago I posted about two techniques to modify your exception template in ColdFusion MX7. The first technique allowed you to have automatically collapsed stack traces with Firefox, like you do with IE. Unfortunately this didn’t make it into 7.0.1, so you will need to reapply the mod if you want to keep using it. The second modification was a bit more complicated. For some reason, I tend to make a common mistake pretty often - I’ll use a key from a structure where the key doesn’t exist. I’m not sure why, but it’s something I do. The modification I had created will notice that error, and then dump the keys of the struct. So if you try to use “FOO” where the keys are “GOO,MOO”, it will be much more evident.

Well, my mod no longer works in 7.0.1. It seems that “caller”, which used to point to the template causing the error, now seems to point to something else in 7.0.1. I could be wrong, but there seems to be no way to get to the template causing the error from the exception template. However, I did notice that the struct itself, the one I tried to use a bad key on, did exist in the error structure. So, I’ve modified my code a bit, and it seems to work fine now, but as always, use with caution. You will want to add the code block after the dump of attributes.message on lines 118-120. I’ve included those lines in the code block below.

<h1 id="textSection1" style="COLOR: black; FONT: 13pt/15pt verdana"> #attributes.message# </h1> <!--- is struct? ---> <cfif findNoCase("is undefined in", attributes.message)> <cfset theVar = listLast(attributes.message," ")> <!--- get rid of period ---> <cfset theVar = left(theVar, len(theVar)-1)> <!--- container would be the struct we used. ---> <cfif structKeyExists(attributes.error, "container") and isStruct(attributes.error.container)> <cfset scope = attributes.error.container> <cfif not structIsEmpty(scope)> Valid keys are: #listSort(structKeyList(scope),"textnocase")# <cfelse> #theVar# is an empty struct. </cfif> </cfif> </cfif>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments