Error and Missing Template handler Not working

73 views
Skip to first unread message

cfwheelsnubee

unread,
Nov 11, 2020, 10:14:43 AM11/11/20
to CFWheels
Good morning all.

I have inherited a very old CFWHEELS app (over 10 years old).

I am trying to get the Error and Missing Template handlers  to work and have tried everything and they just don't fire off.

Here is my onerror code

<cffunction name="onError" returntype="void" access="public" output="true">
    <cfargument name="exception" type="any" required="true">
    <cfargument name="eventName" type="any" required="true">
    <cfscript>
        var loc = {};

        // in case the error was caused by a timeout we have to add extra time for error handling.
        // we have to check if onErrorRequestTimeout exists since errors can be triggered before the application.wheels struct has been created.
        loc.requestTimeout = 70;
        if (StructKeyExists(application"wheels") && StructKeyExists(application.wheels, "onErrorRequestTimeout"))
        {
            loc.requestTimeout = application.wheels.onErrorRequestTimeout;
        }
        $setting(requestTimeout=loc.requestTimeout);

        loc.lockName = "reloadLock" & application.applicationName;
        loc.rv = $simpleLock(name=loc.lockName, execute="$runOnError"executeArgs=argumentstype="readOnly"timeout=180);
    </cfscript>
    <cfoutput>
        #loc.rv#
    </cfoutput>
</cffunction>

<cffunction name="$runOnError" returntype="string" access="public" output="false">
    <cfargument name="exception" type="any" required="true">
    <cfargument name="eventName" type="any" required="true">
    <cfscript>
        var loc = {};
        if (StructKeyExists(application"wheels") && StructKeyExists(application.wheels, "initialized"))
        {
            if (application.wheels.sendEmailOnError && Len(application.wheels.errorEmailAddress))
            {
                loc.mailArgs = {};
                $args(name="sendEmail"args=loc.mailArgs);
                if (StructKeyExists(application.wheels, "errorEmailServer") && Len(application.wheels.errorEmailServer))
                {
                    loc.mailArgs.server = application.wheels.errorEmailServer;
                }
                loc.mailArgs.from = application.wheels.errorEmailAddress;
                loc.mailArgs.to = application.wheels.errorEmailAddress;
                loc.mailArgs.subject = application.wheels.errorEmailSubject;
                loc.mailArgs.type = "html";
                loc.mailArgs.tagContent = $includeAndReturnOutput($template="wheels/events/onerror/cfmlerror.cfm"exception=arguments.exception);
                StructDelete(loc.mailArgs, "layouts"false);
                StructDelete(loc.mailArgs, "detectMultiPart"false);
                try
                {
                    $mail(argumentCollection=loc.mailArgs);
                }
                catch (any e) {}
            }
            if (application.wheels.showErrorInformation)
            {
                if (StructKeyExists(arguments.exception, "rootCause") && Left(arguments.exception.rootCause.type, 6) == "Wheels")
                {
                    loc.wheelsError = arguments.exception.rootCause;
                }
                else if (StructKeyExists(arguments.exception, "cause") && StructKeyExists(arguments.exception.cause, "rootCause") && Left(arguments.exception.cause.rootCause.type, 6) == "Wheels")
                {
                    loc.wheelsError = arguments.exception.cause.rootCause;
                }
                if (StructKeyExists(loc"wheelsError"))
                {
                    loc.rv = $includeAndReturnOutput($template="wheels/styles/header.cfm");
                    loc.rv &= $includeAndReturnOutput($template="wheels/events/onerror/wheelserror.cfm"wheelsError=loc.wheelsError);
                    loc.rv &= $includeAndReturnOutput($template="wheels/styles/footer.cfm");
                }
                else
                {
                    $throw(object=arguments.exception);
                }
            }
            else
            {
                $header(statusCode=500statusText="Internal Server Error");
                loc.rv = $includeAndReturnOutput($template="#application.wheels.eventPath#/onerror.cfm"exception=arguments.exception, eventName=arguments.eventName);
            }
        }
        else
        {
            $throw(object=arguments.exception);
        }
    </cfscript>
    <cfreturn loc.rv>
</cffunction>

And they are called in wheels/functions

<cfset this.name = Hash(GetDirectoryFromPath(GetBaseTemplatePath()))>
<cfset this.mappings["/wheelsMapping"] = GetDirectoryFromPath(GetBaseTemplatePath()) & "wheels">
<cfset this.sessionManagement = true>
<cfif StructKeyExists(server"railo") OR StructKeyExists(server"lucee")>
    <cfinclude template="../config/app.cfm">
    <cfinclude template="controller/appfunctions.cfm">
    <cfinclude template="global/appfunctions.cfm">
    <cfinclude template="events/onapplicationend.cfm">
    <cfinclude template="events/onapplicationstart.cfm">
    <cfinclude template="events/onerror.cfm">
    <cfinclude template="events/onmissingtemplate.cfm">
    <cfinclude template="events/onsessionend.cfm">
    <cfinclude template="events/onsessionstart.cfm">
    <cfinclude template="events/onrequest.cfm">
    <cfinclude template="events/onrequestend.cfm">
    <cfinclude template="events/onrequeststart.cfm">
<cfelse>
    <cfinclude template="config/app.cfm">
    <cfinclude template="wheels/controller/appfunctions.cfm">
    <cfinclude template="wheels/global/appfunctions.cfm">
    <cfinclude template="wheels/events/onapplicationend.cfm">
    <cfinclude template="wheels/events/onapplicationstart.cfm">
    <cfinclude template="wheels/events/onerror.cfm">
    <cfinclude template="wheels/events/onmissingtemplate.cfm">
    <cfinclude template="wheels/events/onsessionend.cfm">
    <cfinclude template="wheels/events/onsessionstart.cfm">
    <cfinclude template="wheels/events/onrequest.cfm">
    <cfinclude template="wheels/events/onrequestend.cfm">
    <cfinclude template="wheels/events/onrequeststart.cfm">
</cfif>

Any suggestions?


Tom King

unread,
Nov 11, 2020, 10:39:00 AM11/11/20
to CFWheels

When you say they don't work, what *do* you get when you do cfthrow() ?
What environment mode are you in? The main error handlers (which send emails + display the "nice" message) will only kick off in production; development/design should just output the native error stacktrace.
If you're getting a white screen, it might be a server configuration issue (like secure error template handling).

So - which version of wheels + what CF engine?
T

Message has been deleted

cfwheelsnubee

unread,
Nov 11, 2020, 12:49:43 PM11/11/20
to CFWheels
I just created an error and was actually able to verify that the onerror.cfm is being called. The message shows in the console but not on the page. Now I need to get the missing template file to show. FYI - it doesn't show in production either.

Tom King

unread,
Nov 11, 2020, 1:19:54 PM11/11/20
to CFWheels
Can you clarify about "showing in console"? Are you calling it via JS?
It might be if you're on a old version of wheels that you need to bufferoutput = true in your application settings.
Lucee recently updated this (5.3) not sure about ACF. In config/app.cfm add this.bufferOutput = true; and reload - that may well help
T

cfwheelsnubee

unread,
Nov 11, 2020, 1:23:01 PM11/11/20
to CFWheels
Sorry. In the developer tools. I am getting closer. Got it to work in Chrome. It may be cached in IE. Will try the bufferoutput. Thanks
Reply all
Reply to author
Forward
0 new messages