Lucee strips the cause from exceptions when casting them in some instances

Description

The toPageException(Throwable) method in railo.runtime.op.Caster is losing the cause of my IOExceptions for the code in my Cache extension. For instance, when there is an error in the init() method for my cache, I am catching it and rethrowing wrapped in an IOException like so:

try { // Init cache here } catch (Throwable e) { throw( new IOException("Error initializing Cache.",e)); }

I would expect the error that's reported to the user and output in the logs to be something along these lines:

java.io.IOException: Error initializing Cache.
at ortus.extension.cache.couchbase.CouchbaseCache.init(Unknown Source)
...
Caused by: ACTUAL USEFUL CAUSE
...

However, what is actually logged and displayed looks like so:

Error initializing Cache.
at ortus.extension.cache.couchbase.CouchbaseCache.init(Unknown Source)
...

From that, it is impossible to tell what actually happened. It appears that many places in Railo's source (CachePut.java is one example), a checked exception is rethrown like so:

try { // Do something } catch (Exception e) { throw Caster.toPageException(e); }

I don't understand everything in the toPageException() method, but if the incoming Throwable is not of type PageException, PageExceptionBox, InvocationTargetException, ExceptionInInitializerError, or ExecutionException, a new NativeException is created which is stripping off the useful cause from my exception and the top-level exception is all that makes it to the user and into the logs. Interestingly enough, the following code is there but commented out:

//Throwable cause = t.getCause(); //if(cause!=null && cause!=t) return toPageException(cause);

Is there a reason the current behavior loses the cause, or is it just an oversight? The expectation is that when I throw an exception that is created with a cause, the cause will be in tact when my Exception is presented to the user/application error/handling.

Environment

None

Activity

Brad Wood 28 November 2016 at 04:50
Edited

Please see the post on this thread by Michael on November 26th. He's getting an NPE on Lucee 5.2 snapshot while casing an exception. Is it possible this ticket introduce a bug?
https://groups.google.com/d/msg/lucee/y7_ZLaCO7bQ/49xBFUMwCAAJ

Michael Offner 14 November 2016 at 18:22

we will change the impl so you have the complete history on java level AND on CFML level.

On CFML level the CatchBlock Object will get a *new key called "Cause", that return an other CatchBlock object holding the cause (if there is a cause). Like with the other keys in CatchBlock, also this new key is only generated when requested, so we have no performance impact because of that.

in the future we can extend the error template to show the cause history, for the moment we will not change it.
Of course anybody is welcome to do so.

*Because the CatchBlock with NativeException already had a key "Cause" we have to make the Cause CatchBlock convertible to a simple value, so people still can do #cfcatch.cause# as possible in past.

Michael Offner 14 November 2016 at 17:51
Edited

RuntimeException=createObject('java','java.lang.RuntimeException'); IOException=createObject('java','java.io.IOException'); Caster=createObject('java','lucee.runtime.op.Caster'); re=RuntimeException.init('RuntimeException:message'); ioe=IOException.init("IOException:message",re); ioe2=IOException.init("IOException2:message",ioe); pe=Caster.toPageException(ioe2); // dump pageException dump(pe.getClass().getName()); dump(pe.getMessage()); // cause cause=pe.getCause(); dump(cause.getClass().getName()); dump(cause.getMessage()); // cause cause=ioe2.getCause(); dump(cause.getClass().getName()); dump(cause.getMessage());
Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Created 22 July 2015 at 19:28
Updated 12 April 2025 at 08:46
Resolved 21 November 2016 at 22:26