Exception Service suggestion

Luis, I would like to have the setting for customEmailBugReport and CustomErrorTemplate work the same way that settings like models.definitionFile file work where the file is first looked for as a relative path after the app mapping, and then secondarily look for as an absolute path.

I have more than one site that shares the same customEmailBugReport file and CustomErrorTemplate file, yet I have to have a copy of that template in each site because I cannot reference an external path.
Also, the cfincludes in the ExceptionService in both the renderBugReportand renderEmailBugReportmethods are not very tolerant of empty app mappings, and end up with multiple forward slashes.

I borrowed logic heavily from the portion of the beanFactory that includes the models.definitionFile and now my ExceptionService allows me to have external files for my customEmailBugReport and CustomErrorTemplate settings. I pasted in the relevant methods at the bottom this E-mail even though the formatting will probably go to crap. I also attached my ExceptionService.cfc but I don’t know if attachments actually work on Google Groups.

And finally, you might notice that I added the following line of code in renderEmailBugReport right inside of the cfcatch:
<cfset controller.setSetting(“CustomEmailBugReport”,"")>

You may not want to keep that line, but if you call the renderEmailBugReport method from within a LogBox appender (which we do) you will get an endless recursive loop if you encounter any errors including the bugReport template since the try/catch in renderEmailBugReport calls the exceptionHandler method, which in turn, logs the error via logbox. Another alternative would be some sort of recursion detection.

At any rate, I have commited these changes to my app, so I implore you to consider them for ColdBox core so I don’t have to keep making them locally everytime I update. :slight_smile:

(Note, if you merge these into your local copy, do it line-by-line as there are a couple un-related changes in this file on the nightly build regarding the exceptionBean CFC path and I am on RC1)

Thanks!

~Brad

<cfif Exception.getErrortype() eq “application” and CustomErrorTemplate neq “”>

<cfif len(controller.getSetting(‘AppMapping’)) >
<cfset appLocPrefix = appLocPrefix & controller.getSetting(‘AppMapping’) & “/”>

<cfset bugReportTemplatePath = appLocPrefix & reReplace(CustomErrorTemplate,"^/","")>
<cfif NOT fileExists(expandPath(bugReportTemplatePath))>

<cfset event.setvalue(“exceptionBean”,Exception)>



<cfset exception = ExceptionHandler(cfcatch,“Application”,“Error creating custom error template.”)>







<cfif Exception.getErrortype() eq “application” and controller.getSetting(“CustomEmailBugReport”) neq “”>

<cfif len(controller.getSetting(‘AppMapping’)) >
<cfset appLocPrefix = appLocPrefix & controller.getSetting(‘AppMapping’) & “/”>

<cfset emailBugReportTemplatePath = appLocPrefix & reReplace(customEmailBugReport,"^/","")>
<cfif NOT fileExists(expandPath(emailBugReportTemplatePath))>

<cfset event.setvalue(“exceptionBean”,Exception)>



<cfset controller.setSetting(“CustomEmailBugReport”,"")>
<cfset exception = ExceptionHandler(cfcatch,“Application”,“Error creating custom email bug report.”)>







ExceptionService.cfc (8.17 KB)

Brad this looks like a great addition just in time to rc2. However is there a way you can do a git pull request?

Hmm, I can try. Will I need to sign up on github and fork first?

~Brad

Hmm, I think so, maybe a pain, but since you contribute so much, I would love more contributions from you, plus it is super easy to integrate for me via git, test and then recomitt.

Fair enough. I’ll give it a try, but it might be after this weekend. I’m swamped under two different deadlines right now. :slight_smile:

~Brad