Lucee has 6 has a great new feature, being able to...
# lucee
z
Lucee has 6 has a great new feature, being able to add a cause to an exception https://luceeserver.atlassian.net/browse/LDEV-438 What does this mean? You can catch an error and then throw another error and add the original exception into the new error i.e. something like a database error blows up, you can then throw a nice error saying duplicate user and then include the original exception an example and how to do this in older lucee versions https://trycf.com/gist/ec53d0f523690c645ae8fe518e89f0b5/lucee5?theme=monokai
⭐ 6
❤️ 2
💯 1
a
CFML has been needing this for years.
💯 3
z
micha has been wanting to add this for ages and we decided to add it despite the code freeze on 6 as we are in RC mode
❤️ 1
e
that is BEYOND COOL!!!
d
What would be really cool is if it reported the line numbers from the original exception instead of the manual throw message. For example, in your above TryCF example, you get:
Copy code
12: // create the exception
13: try {
14: throw msg;
15: }
16: catch(e) {
But it would be cool if that information was from the
cause
exception. That's one that thing I've always hated about rethrowing an exception, because you loose the original in the exception message.
z
with lucee 6, it's a bit different (with a slight bug) this is the output from
Copy code
<cfscript>    
    try {
        throw "upsi dupsi!";
    }
    catch(e) {        
        try {
            throw("Upseli dupseli", e);
        }
        catch(e) {
            // i'm just catching and echo the exception because trycf would swollow most of it 
            echo(e);
        }
    }
    </cfscript>
which is due to the nesting, the bottom looks like
e
Other than the german, which I do not read, that is a massive improvement for this feature. Really, way cool Zackster
z
that's a swiss german, I'm just the messenger, it's @micha who came up with the idea and implemented it
e
Well, either way You and @micha = heroes.
🙏 1
z
we couldn't manage it without @pothys-mitrahsoft either!
a
I think it was @bdw429s who "came up with the idea", or perhaps it was Most Other Languages That Have The Concept of Exceptions who probably landed it first. I mean even ColdFusion has returned rootcause exceptions for its internal stuff forever. It's just never allowed in
<cfthrow>
before.
This is not really "innovation" it's "catching up". It's good. But let's see it for what it is.
z
yeah, it's a common pattern in java. in the image extension, we even have multi caused bys to help debug the various codecs we are using
👍 1
b
@dswitzer The line number of the cause is there, it's just in the "caused by" portion of the stack
Copy code
Caused by: lucee.runtime.exp.CustomTypeException: upsi dupsi!
  at lucee.runtime.tag.Throw._doStartTag(Throw.java:212)
  at lucee.runtime.tag.Throw.doStartTag(Throw.java:201)
  at main1694541623313_5339a523_6780_d030_efc3_284745fd49e5_cfm7020$cf.call(/obscure_ram_path/main1694541623313-5339a523-6780-d030-efc3-284745fd49e5.cfm:28)
Now, what would be handy is if Lucee's error template gave you a quick overview of the causes (there can be any number of nested causes) at the top of the page instead of making you scroll. I think I brought up that idea quite a while ago.
a
I'm in two minds as to whether it should do too much work here. Once one knows where the unhandled exception is being thrown, is it kinda on the dev to go investigate?
z
it's good for summaries to omit some of the verbose undertow / tomcat guff, but it's also important that the raw stack is available The Lucee 6.0 test runner snips out that in the github aciton summary https://github.com/lucee/Lucee/actions/runs/5800154012 at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2449) at lucee.runtime.functions.system.InternalRequest.call(InternalRequest.java:135) at tickets.ldev0881_cfc$cf.udfCall(/test/tickets/LDEV0881.cfc:26) ... omitted verbose (ant / pagecontext / testbox) default stacktraces ... Caused by: org.h2.jdbc.JdbcSQLException: Error opening database: "Concurrent update" [8000-172] ... 139 more
a
"available", sure. "displayed on the screen in the error message", I'm not so sure. (context: I'm only talking about the
cause
exception here, not the unhandled one) But like I said, when I say "not so sure", I do mean "not so sure". That's not code for "I think it shouldn't". Just offering a contrary opinion in a "12 Angry Men" sort of way, to engender thought/conversation
z
in this context, in the test output, you have the full stack https://github.com/lucee/Lucee/actions/runs/5800154012/job/15721642088#step:20:1117
what i do in my log viewer is a bit of parsing and then hiding the bulk of the stack behind some dhtml
👍 1