2013-08-01 74 views
0

返回一個隱含的結構時,基礎錯誤的ColdFusion

我運行一個CF10u10盒與Apache作爲我的本地機器上的Web服務器。我是cfscript的粉絲,並且儘可能地使用新的隱式struct {}聲明Vs structNew()。

守則

文件是一個組件和一個CFM。

componentFile.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"/> 

的問題

解析器拋出一個錯誤,說明詳細cfcatch未定義用於blahImplicit () 方法。但對於其餘的方法

凡爲在blahExplicit()的代碼,script_blahExplicit(),script_blahImplicit()只是正常工作都不錯。

問題

這究竟是爲什麼?爲什麼即使不運行代碼,CF也會拋出錯誤?它在解析時本身拋出錯誤。我使用ACF Builder,發現一旦達到嘗試,控制跳到捕獲

這是一個已知的問題或新的東西?爲什麼返回一個隱含的結構體的問題?

截圖 Error with Implicit Struct

堆棧跟蹤

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。我提交了bug to Adobe

+0

你請可以包括實際的錯誤信息,而不是僅僅描述它。請包括堆棧跟蹤的最初部分,請。 –

+0

@AdamCameron做到了主人:) – Sanjeev

+0

好消息是我可以在CF9上覆制這個,所以可以使用它。感謝真正好的repro例子,順便說一句。 –

回答

1

這絕對是一個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>