Search code examples
coldfusionmura

Allow theme level 'EventHandler.cfc' to raise exceptions in MURA CMS 6?


Can anyone tell me, how I can enable exception handling in the theme level EventHandler.cfc in MURA CMS 6?

I have already had to remove the error handling in the Application.cfc error method, because the default routine wasn't displaying enough error detail. But, it seems like the whole CFC framework is wrapped in a <CFTRY> block, which quite frankly is bizarre.

I would prefer a solution that does not involve using <CFCATCH> to dump the errors to a file, which is the temporary solution that I am using at the moment.

I just want Adobe ColdFusion to behave the way it does with my non MURA websites. When there is an error in a CFC, it just displays it, plain & simple.

Of course, for production, my approach is different.

UPDATE:

Just to let you know, I am using Adobe ColdFusion 11, with robust error handling turned on, so I know for fact that this issue is nothing to do with Adobe ColdFusion. It is definitely a MURA CMS issue.


Solution

  • Don't remove the built-in error handling. They have put that in place to protect you from information disclosure. Instead make changes to the error handling to suit your needs.

    Mura comes with basically three levels of error "catching". At the theme level, at the site level and then globally. (And I have found that even though an error may be caught at a lower level like 'site' that does not prevent the same error from bubbling up and also firing the 'global' handler.)

    Steve Withington created a Gist example that should help you get started. See it here. Be sure to read the comments in the code as it explains where the files live and any configuration settings necessary to invoke them.

    Copying his code examples here in case that resource is taken down in the future.
    Credit Steve Withington

    Mura Error Handling: You could use any or even both of the attached methods to help with error handling in Mura CMS. This works better than the default "We're sorry, an error has occurred. Please try again later."

    muraCustomErrorFile.cfm

    <!---
        1) Drop this file under /config/ directory.
        2) Add errortemplate=/muraWRM/config/customErrorFile.cfm to the settings.ini.cfm file.
        3) Set debuggingenabled=false in the settings.ini.cfm file.
        4) Reload Mura CMS
    --->
    <cftry>
        <cfset msg = 'MURA ERROR - MESSAGE: #arguments.exception.Message#  DETAIL: #arguments.exception.Detail# ' />
        <cflog type="ERROR" file="MuraError" text="#msg#" />
        <cfcatch></cfcatch>
    </cftry>
    <cfparam name="url.debug" default="false" />
    <cfoutput>
    <!DOCTYPE html>
    <html>
        <head>
            <title>Site Down For Maintenance</title>
        </head>
        <body>
    
            <h3>Site Down for Maintenance</h3>
    
            <cfif url.debug>
                <cfdump var="#arguments#" />
    
                <!--- You Have Access to arguments.eventName and aguments.exception --->
                <!---
                <h4>Exception Message</h4>
                <p>#arguments.exception.message#</p>
    
                <h4>Exception Detail</h4>
                <p>#arguments.exception.detail#</p>
    
                <h4>TagContext[1]</h4>
                <cfdump var="#arguments.exception.TagContext[1]#" />
                --->
    
                <!--- you could also dump whatever else you want to inspect --->
                <!---
                <cfdump var="#cgi#" label="CGI" />
                <cfdump var="#request#" label="REQUEST" />
                <cfdump var="#session#" label="SESSION" />
                <cfdump var="#application#" label="APPLICATION" />
                --->
    
            <cfelse>
    
                <p>This site is temporarily down for maintenance.</p>
    
            </cfif>
    
        </body>
    </html>
    </cfoutput>
    

    muraOnGlobalError.cfm

    <cfscript>
    // drop this method in either the Site or Theme eventHandler.cfc
    
    public any function onGlobalError($) {
        var tagContext = '';
        var local = {};
    
        param name='url.debug' default=false;
    
        local.ex = arguments.$.event('exception');
    
        local.errorMessage = 'GLOBAL ERROR - MESSAGE: #local.ex.Message#  DETAIL: #local.ex.Detail# ';
    
        try {
            tagContext = local.ex.TagContext[1];
        } catch(any e) {};
    
        if ( IsStruct(tagContext) ) {
            local.errorMessage = local.errorMessage & '  
                LINE: #tagContext.LINE#  
                TEMPLATE: #tagContext.TEMPLATE#  
                RAW_TRACE: #tagContext.RAW_TRACE#';
        }
    
        WriteLog(type='ERROR', file='muraGlobalError', text='#local.errorMessage#');
    
        if ( url.debug ) {
            WriteOutput('<h2>Debug Output</h2>' & local.errorMessage);
            WriteDump(var=arguments, label='ARGUMENTS', abort=1);
        }
    }
    </cfscript>