Issue with serialize(Struct):String

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#

Here is the full include:

<cfscript>
   qBreadcrumbs=QueryNew("url,title", "varchar,varchar");
   link="/";
</cfscript>



<cfloop list="#cgi.SCRIPT_NAME#" delimiters="/" index="i">
    <cfscript>
       QueryAddRow(qBreadcrumbs, 1);
       QuerySetCell(qBreadcrumbs, "url", link & i);
       QuerySetCell(qBreadcrumbs, "title", "#replace(replace(i, '_', ' ', 'all'), '.cfm', '', 'all')#");
       link=link & i & '/';
    </cfscript>
</cfloop>


<cfoutput>
<div id="breadcrumbs">
  <cfset totalCrumbs = qBreadcrumbs.recordcount>
  <cfset crumbCounter = 1>
  <nav aria-label="breadcrumb">
  <cfif #qBreadcrumbs.recordcount# GT 1><p><a href="/" title="Home">Home</a>
    <cfloop query="qBreadcrumbs">
      <cfset #thisIsNotTheLastCrumb# = ( #crumbCounter# LT #totalCrumbs# )>

        <cfoutput>

            <cfif #title# NEQ "index" and #title# NEQ "views"><cfif #thisIsNotTheLastCrumb#><a href="#url#" title="#title#">#title#</a><cfelse>
            #title#</cfif></cfif>
                    <cfset #crumbCounter#++>
        </cfoutput>

    </cfloop>
    </p>
  </cfif>
</nav>
</div>
</cfoutput>

Thanks! Any help is appreciated.

@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.

<a href="#qBreadcrumbs.url#" title="#title#">#title#</a>
1 Like

you don’t need the #'s around the variables inside the various cftags, only when outputting html

<cfset #thisIsNotTheLastCrumb# = ( #crumbCounter# LT #totalCrumbs# )>

can be written as

<cfset thisIsNotTheLastCrumb = ( crumbCounter LT totalCrumbs )>

Ahhh thank you! Did not catch that. That makes sense.

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]

there’s quite a few of them

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…”

1 Like

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!

1 Like

bug filed

https://luceeserver.atlassian.net/browse/LDEV-3892