0

基础知识

我在本地机器上运行一个 CF10u10 机器,Apache 作为 Web 服务器。我是 cfscript 的粉丝,并且喜欢尽可能使用新的隐式 struct {} 声明 Vs structNew()。

编码

文件是一个组件和一个 CFM。

组件文件.cfc

<cfcomponent output="false">

    <cffunction name="blahExplicit" returntype="Struct">
        <cfset var name = 'ColdFusion'/>
        <cfset var ret = structNew()/>
        <cftry>
                <cfreturn {success: true, data: name}/>
            <cfcatch type="any">
                <cfset ret.success = false />
                <cfset ret.data = cfcatch />
                <cfreturn ret/>
            </cfcatch>
        </cftry>
    </cffunction>

    <cffunction name="blahImplicit" returntype="Struct">
        <cfset var name = 'ColdFusion'/>
        <cftry>
                <cfreturn {success: true, data: name}/>
            <cfcatch type="any">
                <cfreturn {success: false, data: cfcatch.detail}/>
            </cfcatch>
        </cftry>
    </cffunction>

    <cffunction name="script_blahExplicit" returntype="Struct">
        <cfscript>
            var name = 'ColdFusion';
            var ret = structNew();
            try{
                return {success: true, data: name};
            } catch(Any err){
                    ret.success = false;
                    ret.data = err.detail;
                    return ret;
            }
        </cfscript>
    </cffunction>

    <cffunction name="script_blahImplicit" returntype="Struct">
        <cfscript>
            var name = 'ColdFusion';
            try{
            return {success: true, data: name};
            } catch(Any err){
                return {success: false, data: err.detail};
            }
        </cfscript>
    </cffunction>
</cfcomponent>

cfcatchErr.cfm

<cfset cObj = createObject("component","componentFile")/>
<cfdump var="#cObj.blahExplicit()#" label="blah Explicit"/>
<cfdump var="#cObj.script_blahExplicit()#" label="blah Explicit With Script"/>
<cfdump var="#cObj.script_blahImplicit()#" label="blah Implicit With Script"/>
<cfdump var="#cObj.blahImplicit()#" label="blah Implicit"/>

问题

解析器抛出一个错误,说明blahImplicit() 方法的 cfcatch未定义详细信息。但是剩下的方法都可以

blahExplicit(),script_blahExplicit(),script_blahImplicit() 中的代码工作正常

问题

为什么会这样?为什么即使没有运行代码 CF 也会抛出错误?它本身在解析时抛出错误。我使用 ACF Builder 发现控件一到达try就会跳转到catch

这是一个已知问题还是新问题?为什么返回隐式结构是个问题?

截屏 隐式结构错误

堆栈跟踪

coldfusion.runtime.UndefinedElementException: Element DETAIL is undefined in CFCATCH.
    at coldfusion.runtime.CfJspPage.resolveCanonicalName(CfJspPage.java:1752)
    at coldfusion.runtime.CfJspPage._resolve(CfJspPage.java:1705)
    at coldfusion.runtime.CfJspPage._resolveAndAutoscalarize(CfJspPage.java:1854)
    at coldfusion.runtime.CfJspPage._resolveAndAutoscalarize(CfJspPage.java:1833)
    at cfcomponentFile2ecfc947108420$funcBLAHIMPLICIT.runFunction(C:\ColdFusion10\cfusion\wwwroot\fresh\componentFile.cfc:21)
    at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
    at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
    at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
    at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
    at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
    at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
    at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655)
    at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444)
    at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414)
    at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432)
    at cf62ecfm1194236173.runPage(C:\ColdFusion10\cfusion\wwwroot\fresh\cfcatchErr.cfm:5)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244)
    at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444)
    at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
    at coldfusion.filter.IpFilter.invoke(IpFilter.java:64)
    at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:449)
    at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
    at coldfusion.filter.PathFilter.invoke(PathFilter.java:112)
    at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
    at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
    at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
    at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
    at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
    at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
    at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
    at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
    at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
    at coldfusion.CfmServlet.service(CfmServlet.java:219)
    at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
    at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414)
    at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:204)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

注意:我也喜欢 Railo,但在这种情况下我们只讨论 CF 10。我向Adob​​e 提交了一个错误

4

1 回答 1

2

这绝对是 CF 中的一个错误,非常好,以至于您将其记录为这样(3605215)。

我能想到的最方便的解决方法是使用中间变量,例如:

<cffunction name="blahImplicit" returntype="Struct">
    <cfset var name = 'ColdFusion'/>
    <cftry>
            <cfreturn {success= true, data= name}>
        <cfcatch type="any">
        <cfset var ret = {success= false, data= cfcatch.detail}><!--- this will prevent the error --->
            <cfreturn ret>
        </cfcatch>
    </cftry>
</cffunction>
于 2013-08-01T07:33:41.263 回答