I have the following include that generates breadcrumbs. It works fine in CF2018, but moving over to lucee I am getting the errors: Can’t cast Complex Object Type Struct to String, Use Built-In-Function “serialize(Struct):String” to create a String from Struct.
I understand what theya re saying but trying a bunch of options I haven’t been able to fix it yet. Any thoughts on how to fix this? This is the problematic line.
<cfif #title# NEQ “index” and #title# NEQ “views”><cfif #thisIsNotTheLastCrumb#>#title#
@spacerobot Actually problem is in this code <a href="#url#" ......>. ACF takes this as a query column url in the loop. But lucee takes this as url scope. So it throws an error in the lucee.
<a href="#url#" title="#title#">#title#</a>
Using query variable prefix with url variable (like qBreadcrumbs.url) in that line works fine in lucee too.
that reminds me, all these cast error message are horrible and confusing,
we can make them better, something in this direction?
Can't cast variable [ url ] to type [ string ], it's a Complex Object Type [ struct ]
or just Can't cast variable [url] to type [string], it's a [struct]
or
Mate, [url] is a fucking [struct], you can't just automagically convert it to a [string]
I think, what may also be a little confusing is the terminology “object”, because this term also makes reference to instantiated objects and really doesn’t tell that the error it’s about data type conversion.
I’d rather say “complex data type” instead of “complex object” in these errors with a a slightly different version from yours, something like:
Can’t cast the variable [url] to type [string]. because it’s a [struct]. A [struct] is a “complex” data type that can’t be simply converted/casted to a “simple” data type of [string].
Funny, when I try to search for error messages to get examples they are surprisingly hard to find. Maybe I should just go back to coding, they appear much more frequently that way. I like all of the above examples, adding the variable name is very helpful. Indifferent to the term Object. As @andreas mentioned, it should be clear that converting your variable from type struct (complex) to whatever simpler data type is causing the issue. Maybe something like the following:
“Data Conversion Error: Can’t Cast Variable [name] of Complex Type Struct to…”
“Data Conversion Error: Can’t Compare Variable [name] of Complex Type Struct with a…”
Thanks everyone. I love the proposed changes. I think this will definitely help. If it had directed me to URL as a struct I think I would have gotten it at that point!