Error “Kind” Is not At all times A String In Adobe ColdFusion


The day prior to this, whilst running on Dig Deep Health, my ColdFusion health tracker, I by chance fed on an ordered struct as though it have been an array. As anticipated, ColdFusion threw an error; then again, my centralized error dealing with good judgment broke for the reason that sort belongings of the thrown error used to be no longer a string, it used to be a posh Java object. I don’t believe I would ever run into this factor earlier than – I have at all times believed that the sort, message, element, and extendedInfo homes have been assured to be a string. I assume no longer.

This end result is straightforward to breed:

<cfscript>

	take a look at {

		// Create an ORDERED STRUCT.
		records = [:];

		// By chance use it like an ARRAY in CFLOOP.
		cfloop( merchandise = "merchandise", array = records ) {
			// ....
		}

	} catch ( any error ) {

		writeDump( error );

	}

</cfscript>

As you’ll see, I am by chance looping over records as though it have been an array. And, after I take a look at to try this in Adobe ColdFusion, we get the next output:

ColdFusion error data structure that has a Java object as the Type property.

As you’ll see, the Kind belongings at the stuck error isn’t a string however a posh Java object. Sadly, I’ve good judgment in my error dealing with that assumes that this price will at all times be a string; and, that I will name string member strategies on it. It seems that I can’t suppose this to be true.

ASIDE: In Lucee CFML, this does not throw an error as a result of Lucee will fortunately deal with “array like” structs as arrays.

Most definitely, what I wish to do is a cross the mistake object via a “normalization” regimen inside my centralized error dealing with. This manner, I will create an object that has a assured construction (which assured data-types). More or less a bummer; however, we are living and we be informed.

Wish to use code from this publish?
Take a look at the license.



0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Back To Top
0
Would love your thoughts, please comment.x
()
x