exception handling problem

22 views
Skip to first unread message

Brian FitzGerald

unread,
Nov 17, 2013, 9:48:53 AM11/17/13
to mach-ii-for...@googlegroups.com
Hey guys,

I'm rather baffled by this exception handling issue. Basically I have the following exception handling flow:

  • setup generateTestException event which runs invalid statement, i.e. <cfset a = b> where b is undefined
  • mach-ii "exception" event fires
  • custom event-handler "exception" runs
  • Exception.cfc filter runs
    • if productionExceptionHandling is disabled, there are no problems and the exception is dumped out correctly
    • if productionExceptionHandling is enabled, the "pretty" view will only render if it has an abort tag at the bottom, and I can't figure out why the abort tag is necessary.
      • with the abort, the pretty view renders fine
      • without the abort, the request spins until it times out

Thanks in advance for any insight,
Brian

Relevant code: mach-ii.xml (short video demonstrating issue if helpfulhttp://www.screenr.com/maQH)

    <event-handler event="generateTestException">
   <view-page name="exceptions.generateTestException" />
  </event-handler>

  <event-handler event="exception" access="private">
   <filter name="exception" />
  </event-handler>

  <event-handler event="exception.development.default" access="private">
   <view-page name="exceptions.development.default" />
  </event-handler>

  <event-handler event="exception.production.default" access="private">
   <view-page name="exceptions.production.default" />
  </event-handler>
 
  <event-handler event="exception.production.noEventHandler" access="private">
   <view-page name="exceptions.production.default" />
  </event-handler>

Relevant code: Exception.cfc (filter)

<cffunction name="filterEvent" access="public" returntype="boolean" output="true" hint="Writes to log and sends email of exception.">
<cfargument name="event" type="MachII.framework.Event" required="true">
<cfargument name="eventContext" type="MachII.framework.EventContext" required="true">
<cfargument name="paramArgs" type="struct" required="false" default="#StructNew()#">

<cfset var exception = arguments.event.getArg("exception")>
<cfset var caughtException = exception.getCaughtException()>
<cfset var requestName = arguments.event.getRequestName()>
<cfset var exitEvent = "">
   
<!--- Decide if production handling is to be used --->
<cfif isProductionExceptionHandlingEnabled()>
<cfswitch expression="#caughtException.type#">
<!--- Announce event for "bad events" such as spammers messing with URLs or wrongly typed URLs --->
<cfcase value="MachII.framework.EventHandlerNotDefined|MachII.framework.EventHandlerNotAccessible|MachII.framework.ModuleNotDefined|MachII.framework.UrlRouteNotDefined" delimiters="|">
<cfset arguments.eventContext.addHTTPHeaderByStatus("404", "Not Found")>
<cfset exitEvent = "exception.production.noEventHandler">
</cfcase>
<!--- Announce event for completely unhandled exceptions  --->
<cfdefaultcase>
<cfset arguments.eventContext.addHTTPHeaderByStatus("500", "Error")>
<cfset exitEvent = "exception.production.default">
</cfdefaultcase>

</cfswitch>

<cfset getNotificationService().sendExceptionEmail(caughtException)>

<cfelse>
<!--- Announce event with helpful developer exception info --->
<cfset arguments.eventContext.addHTTPHeaderByStatus("500", "Error")>
<cfset exitEvent = "exception.development.default">

</cfif>

<cfset announceEvent(exitEvent, arguments.event.getArgs())>
<cfreturn true>
</cffunction>

Thorsten Frey

unread,
Nov 19, 2013, 2:58:13 PM11/19/13
to mach-ii-for...@googlegroups.com
Hi Brian,

I made a test but I my pages behave as expected. Though there some minor things, you could try.

In cffunction "filterevent" output could be "false";
as I understand the Event-Filter cfreturn should be "false" as you announce a new event.

In your viewPage on the top your code is: <
cfprocessingdirective pageencoding = "utf-8" >
The tag should be closed <cfprocessingdirective pageencoding = "utf-8" />

In my test page, it made no difference ..

Thorsten

Brian FitzGerald

unread,
Nov 19, 2013, 3:55:37 PM11/19/13
to mach-ii-for...@googlegroups.com
Hey Thorsten,

Thanks a lot for your response and ideas - I really appreciate it!

I'm gonna mess around with the stuff you suggested and see what I find out.

Best,
Brian
Reply all
Reply to author
Forward
0 new messages