Improving Lucee Exceptions / Developer Experience

Sometimes the exceptions Lucee throws are confusing or need more context

Improving the developer experience with Lucee is an important focus for us,
what else can we improve on?

Improved Exceptions

I think all of us have been on magical mystery tours searching for the source of an exception in the exception.log, so we’ve been working on making your life as a Lucee developer easier!

One nice improvement in 6.2 is that the AbstrCFMLExprTransformer exception now includes the context, i.e. filename and line number

[java]    [script] Failed: test.tickets.LDEV1783
 [java]    [script]   Checking exception includes template
 [java]    [script]   Expected [success] but received [lucee.runtime.exp.TemplateException: 
 Too few arguments in function call [min]; 
Failed in D:\\work\\lucee7\\test\\tickets\\LDEV1783\\LDEV1783.cfm:2
 [java]    [script]         at lucee.transformer.cfml.expression.AbstrCFMLExprTransformer.getFunctionMember(AbstrCFMLExprTransformer.java:1911)
 [java]    [script]         at lucee.transformer.cfml.expression.AbstrCFMLExprTransformer.startElement(AbstrCFMLExprTransformer.java:1687)
 [java]    [script]         at lucee.transformer.cfml.expression.AbstrCFMLExprTransformer.dynamic(AbstrCFMLExprTransformer.java:1310)
 [java]    [script]         at lucee.transformer.cfml.expression.AbstrCFMLExprTransformer.checker(AbstrCFMLExprTransformer.java:997)
 [java]    [script]         at lucee.transformer.cfml.expression.AbstrCFMLExprTransformer.clip(AbstrCFMLExprTransformer.java:953)
 [java]    [script]         at lucee.transformer.cfml.expression.AbstrCFMLExprTransformer.negatePlusMinusOp(AbstrCFMLExprTransformer.java:9

https://luceeserver.atlassian.net/browse/LDEV-1783

Also in 6.2, we improved compiler exceptions

Errored: Invalid Syntax Closing [}] for function [_literalstruct] 
not found [s] at position [627]

previously was only

Errored: Invalid Syntax Closing [}] for function [_literalstruct] not found

https://luceeserver.atlassian.net/browse/LDEV-4929

In Lucee 6.0 we added context to failed json deserialization

https://luceeserver.atlassian.net/browse/LDEV-4225

Lucee 6.0 also adds cause to <cfthrow> so you can throw more meaningful exceptions yourself

https://luceeserver.atlassian.net/browse/LDEV-1075

and lastly, but not least, being able to easily force all logging to the console

https://luceeserver.atlassian.net/browse/LDEV-3420

11 Likes

Lucee 7 now reports the position of the end tag when a start and end tag doesn’t match

was

Start and End Tag has not the same Name [cfoutput-cfif]; 
Failed at [D:\work\lucee7\core\src\main\cfml\context\admin\overview.cfm:289]

now

Start and End Tag do not match [cfoutput-cfif], 
mismatched closing Tag at line [534]; 
Failed at [D:\work\lucee7\core\src\main\cfml\context\admin\overview.cfm:245]

https://luceeserver.atlassian.net/browse/LDEV-5697

Let me know if you encounter other exceptions we can improve!

7 Likes

This is great! I know I’ve had a few rounds of “comment everything out” and then slowly start to comment things back-in until a syntax error is better identified. This will be very helpful.

Spoiler alert: it’s always a missing comma.

4 Likes

Hey Ben, come to think of it, I should rename myself Missing Comma.

A constant reminder my brain’s syntax needs reviewing. LOL!

And thanks for the update Zackster!

1 Like

Added a few more improvements to 7

All these functions now report back the list of supported algorithms (depending on your JVM), when there’s an exception

i.e.

Invalid call of the function [GenerateSecretKey], 
first Argument [badAlgorithm] is invalid, 
The algorithm [badAlgorithm] is not supported. 
Supported algorithms  are [ HmacSHA3-224, HmacSHA384, 
HmacSHA512/224,  HmacSHA512, HmacSHA512/256, HmacSHA3-512, 
HmacSHA3-256,  HmacSHA3-384, HmacSHA224, ARCFOUR, Blowfish,  
HmacSHA256, HmacSHA1, AES, HmacMD5, DESede, DES, RC2, ChaCha20 ]
4 Likes

7.0.2.51-SNAPSHOT adds some context to the at times confusing Can't cast Complex Object Type Struct to String exception

The most common version of this is using scope names as a variable, i.e. url

url = "http://localhost:8888";
cfhttp( url=url ); // tries to pass URL scope struct instead of the string
// BEFORE: "Can't cast Complex Object Type Struct to String"

This happens because scope names are reserved words, but the exception messages was confusing

Reserved Words :: Lucee Documentation

This PR adds contextual info to the exception

// AFTER:  "Can't cast Complex Object Type [URL scope] to String"     

https://luceeserver.atlassian.net/browse/LDEV-3892?focusedCommentId=72639

3 Likes