Reserved Words in AOP Aspects

If you are new to Aspect Oriented Programming (AOP) in general, I recommend you start here for a crash course.

I was dealing with a strange bug using my QueryToArrayOfStructsConverter in a new project. The code was super simple — just a select * from table as an example for a test I was writing. I expected to get back my array of structs, but I instead got this mysterious error:

Exception mixing in AOP aspect for (TestDAO)

I decided to take the time to dig in to the AOP portion of ColdBox to try to (1) learn about how AOP is implemented in ColdBox and (2) find my problem here.

Side Note:

Whenever I dig in to these packages and frameworks, I’m assuming I’m going to find that I was doing something wrong.
It’s more time consuming than finding an answer in the documentation, but also more enlightening about how the tool I’m using works.

AOP is a fascinating pattern. I was interested to find that ColdBox accomplishes the pattern by writing a dyanmic function to a file and then including that file in the in-memory class using a <cfinclude />. Very smart.

I mention the <cfinclude /> because it was here that I was getting the error. You see, ColdBox is just catching any error and reporting it back as the error message above. By commenting out the try-catch block, we see a different and, in this case, more useful error message:

Better Error Message showing Function Name find was already used by Lucee

Looks like Lucee is using find as a function name under the hood. The method I was trying to join to was also called find. Easy enough fix — I renamed the method to findAll.

There’s probably other reserved words, as it were, that you can’t join an aspect to, but I don’t have a list. What I do have now is a good guess at the problem when I see this kind of error message and a better understanding of how ColdBox puts together AOP.

Reserved Words in AOP Aspects

2 thoughts on “Reserved Words in AOP Aspects

  1. Excellent work. Any ideas on how we can improve the error message that bubbles up? Perhaps part of the original message can be included as the detail in the new error that’s thrown. This is where it would be really nice to be able to nest exceptions in CFML like Java does so you can have one exception that was “CAUSE BY” another deeper one.

Leave a Reply

Your email address will not be published. Required fields are marked *