Uploaded image for project: 'Lucee Development'
  1. LDEV-454

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

    Details

    • Type: Bug
    • Status: Deployed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.1.1.16
    • Labels:
      None

      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.

        Attachments

          Activity

            People

            • Assignee:
              michaeloffner Michael Offner
              Reporter:
              bdw429s Brad Wood
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: