Coldbox and VueJS untangled

Cfcompile to the rescue

This is a story about sloppiness, dislexia, or maybe my touch typing skill are just lacking when coding. I also hear friends telling me their cat is sleeping on the keyboard. To add to this disaster, Lucee is not very helpful when trying to decipher my typo’s. I wonder if you ever saw a screen like this:

We all see these ugly screens sometimes, but usually they provide some information on an error. But not this time…

No filenames, no line numbers, just a stupid syntax error. But in which of the 150+ model files in my project? I’ve seen this error many many times, I even filed a bug with Lucee. They were absolutely sure I shouldn’t see this Lucee parsing error, but the couldn’t reproduce it. First time I met this condition I think I just changed some sixty files before restarting coldbox, and oops… some ugly unhelpful screen. Try to find missing comma’s, semicolons or whatever in this pile of files. It is a lot of work, especially if it something silly like this. Some time ago I posted this in the coldfusion Slack group, and someone advised me to use cfcompile to find the offending file. I don’t remember who it was, but if you meet me at the next not-so-virtual conference I’ll buy you a beer (or two).

cfml-compiler is a nice commandbox utility written by Pete Freitag, and although it looks quite simple it already saved my day many times. So thanks Pete! It can be installed by the simple box command

box install cfml-compiler

and you will have a nice cfcompile command at your service, which will compile all cfml code you throw at it. As a bonus it even tells you in which files you made your syntax errors, so you can fix them. You can compile your whole project, just a few directories or a simple file. The last option is handy if you found the offending file and wanted to check if you corrected all errors. So in this case I suspected something was wrong in my models directory. I created a map for the compiled code outside of my root, since I am not interested in the compiled version, only in the errors. So from my root dir I compiled some code:

cfcompile sourcepath=./models/  destpath=../compiled cfengine=lucee@5.3.5

And this is what I wanted to see:

cfcompile errors

Ok, now I have some more info. In this case I updated my RedirectService. Cfcompile is telling me my error is in line 7 but it is lying as usual. It just means it can’t understand what I am doing from line 7. At least I had my previous version in git, so a quick diff revealed what had changed. Still not so easy to spot, just have a look:

DnsRecordService.new({
  domain_id  : oDnsDomain.getId(),
  type:      : "A",
  content    : REDIRECT_IP_V4,
  shortname  : "www",
  ttl        : 3600
});

I still didn’t see it (that really looks like dyslexia) but finally found it after commenting out every single line. Which brings me to my second favourite tool: cfformat, which applies some nice formatting rules on my badly treated RedirectService. After formatting it looks like this:

DnsRecordService.new( {
  domain_id   : oDnsDomain.getId(),
  type        :  : "A",
  content     : REDIRECT_IP_V4,
  shortname   : "www",
  ttl         : 3600
} );

So if I would cfformat my code directly I would spot this stupid typo’s a lot earlier. I just had two colons on line 3. And since I copied some of this code in a simular way in other files, I multiplied my errors ( don’t repeat yourself, another invaluable rule…)

So problem solved. It is weird cfformat can spot the offending file immediately but when I fire up the same server manually it gets completely lost and errors. I’ve seen this many times, with all Lucee 5.x versions. Not only with double colons, but also missing comma’s in arrays or structs ruined my code several times. And small update: forgetting the > in this arrow function return myDnsTypes.map( ( item ) => { return item.id; } ).toList(); also blows up the error handling. I still don’t understand why I see this in my project and never heard of other people with the same problem. It is just a Lucee error, and because Lucee itself has errors, it doesn’t remember in which file this happened.

Until this is resolved, I try to improve my touch typing skills and keep the cats away from my keyboard. cfcompile remains my friend for a while.

1 Comment

  1. Zac Spitzer

    Nice post! can you file a bug?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2024 ShiftInsert.nl

Theme by Anders NorenUp ↑