Throwing serialized/deserialized exception object loses original stacktrace and tag context

Description

Throwing an existing CFCatch exception object with

throw( object=exception );

will result in a new exception which has the same stack trace and tag context of the original error. However if exception is serialized and them deserialized, using it in a throw will NOT keep the original stack trace and tag context, even though this information is part of the new struct.

https://trycf.com/gist/d94608eaaca61c89bca5422940b3f495/lucee5?theme=monokai

// Create an initial exception try { throw( message="error message", detail="error detail", type="error_type" ); } catch ( any e ) { exception = e } dump('Original Error thrown from #exception.tagContext[1].template#:#exception.tagContext[1].line#' ) // Rethrow the original exception object try { throw( object=exception ); } catch ( any e ) { exception = e } dump('Rethrown Error has original stack/tag context: #exception.tagContext[1].template#:#exception.tagContext[1].line#' ) // now serialize and deserialize the exception to a CFML struct: exception = deserializeJSON( serializeJSON( exception ) ) // Now Rethrow the CFML struct try { throw( object=exception ); } catch ( any e ) { exception = e } dump('This error does not retain the original stack/tag context: #exception.tagContext[1].template#:#exception.tagContext[1].line#' )

The logic for this is here. When the object argument to the throw() call is an actual CFCatch block, this code is run:

https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/runtime/tag/Throw.java#L148

but when the incoming object is just a struct, the stacktrace and tag context keys are not even used:

https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/runtime/tag/Throw.java#L157-L192

It should be possible to parse the stack trace string and re-create an array of StackTraceElement objects that can be set back into the Throwable using setStackTrace().

Environment

None

Activity

Show:

Pothys - MitrahSoft 6 June 2022 at 14:00

I've checked this ticket with the lucee latest version 5.3.10.10-SNAPSHOT. Yes, using serialize/deserialize struct of the original exception in throw() losses the stacktrace and tagContext

I added a testcase to this ticket
Pull Request: https://github.com/lucee/Lucee/pull/1661

Brad Wood 4 June 2022 at 00:15

Details

Assignee

Reporter

Priority

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 3 June 2022 at 23:19
Updated 15 September 2022 at 16:07

Flag notifications