Error on RestHander.cfc adding default value to "exception" arg

Ok, this is the situation

File:

version 6.6.1:

	function onError(
		event,
		rc,
		prc,
		faultAction = "",
		exception,
		eventArguments = {}
	){

from 6.7.0:

	function onError(
		event,
		rc,
		prc,
		faultAction    = "",
		exception      = {},
		eventArguments = {}
	){

Since version 6.7, exception var is never null (because added default value), so line 171 is never executed, even when exception is an empty structure:

170:   if ( isNull( arguments.exception ) && !isNull( arguments.prc.exception ) ) {
171:      arguments.exception = arguments.prc.exception.getExceptionStruct();
172:   }

For this I get an error on line 181:

180: log.error(
181: "Error in base handler (#arguments.faultAction#): #arguments.exception.message# #arguments.exception.detail#",
182: {

key [MESSAGE] doesn't exist

HTH

(So sorry, i wrote too much today :sweat_smile:)

How can I reproduce this?

Yep! Give me some time, I prepare an environment to reproduce it.

Thanks for reply!

Hi @lmajano,
I’ve prepared a package for you that you can run.
You can download from here:
http://www.coridalia.cc/tmp/cb-bug-exception.zip

Ok, let’s start, on CommandBox. Unzip file in a directory and:

install
server start

then, open your browser here:

http://localhost:8198/apps/api/
  1. CB invokes Util.index, and before it invokes “preProcess” in MainInterceptor.

  2. MainInterceptor contains an Error, searches for a key that not exists:
    GetHTTPRequestData().headers['NOT_EXISTS']
    File in apps\api\interceptor\MainInterceptor.cfc

  3. ColdBox invokes util.onError, as configuration. The corrected error message is shown.

  4. Now we reproduce the error:

a) Comment/remove util.onError method in apps\api\controller\AbsController.cfc

b) Now, without util.onError, CB invokes “onError” in RestHandler, where arguments.exception is empty (ad default, not null).
The exception obj is in arguments.prc.exception.getExceptionStruct(), but the line 171 in RestHandler is never run because arguments.exception is empty (default={}), not null.

170:   if ( isNull( arguments.exception ) && !isNull( arguments.prc.exception ) ) {
171:	  arguments.exception = arguments.prc.exception.getExceptionStruct();
172:   }

c) Now, Lucee raises an error, because, in line 181, the key “message” in arguments.exception not exists:

181:  Error in base handler (#arguments.faultAction#): #arguments.exception.message#",

d) at the end, CB invokes “onAnyOtherException” (in my AbsController) and i can view the error in RestHandler. This:


key [MESSAGE] doesn't exist

179: // Log Locally 
180: log.error( 
181: "Error in base handler (#arguments.faultAction#): #arguments.exception.message# #arguments.exception.detail#", 
182: { 
183: "_stacktrace" : arguments.exception.stacktrace,

system.resthandler_cfc$cf.udfCall1(/coldbox/system/RestHandler.cfc:181)

In my opinion, it would be enough to edit line 70 of RestHandler.cfc:

IsNull( arguments.exception )
to
StructIsEmpty( arguments.exception )

I hope it is useful for you.
If you need, do not hesitate to write me.

Thanks for your attention.

WOW! Thanks @Roberto_Marzialetti . This is really amazing. Most of the time we don’t get as much detail or information and it makes our job of resolving bugs so much harder. However, I just want to commend you for taking the time to send us in detail how to replicate the issue.

I will try it and report back.

1 Like

I’m a developer like you @lmajano.
And I hate when my clients say only “not works” :smirk:
Thanks for your huge work.

Hi @Roberto_Marzialetti
I tracked the bug. This was an issue already logged for the 6.x series: [COLDBOX-1145] - Welcome

It is solved in v7. However, since 6 is in LTS I have added the bugfix to the 6.x series as well. You can track it’s build process here: fix: ⚡ COLDBOX-1145 #resolve · ColdBox/coldbox-platform@be940ea · GitHub

I will release this as v6.9.0 this week.

1 Like

@lmajano many thanks!