amphp / parallel

An advanced parallelization library for PHP, enabling efficient multitasking, optimizing resource use, and application responsiveness through multiple CPU threads.
MIT License
779 stars 64 forks source link

Include context backtrace in message #168

Closed trowski closed 1 year ago

trowski commented 1 year ago

PHP does not call __toString() on a previous exception, so our decision to wrap ContextPanicError in a ContextException had the unfortunate side-effect of removing the context trace from the output of an uncaught exception.

There's a couple ways we can approach this. This PR puts the trace as a string into the message. This has the side-effect of needing to create a stack-trace string for uncaught exceptions from Tasks, but is mostly negligible I'd think.

Another approach would be to use reflection to set the $trace property of the parent exception, forcing the child trace to be the trace of the ContextPanicError object.

(new \ReflectionProperty(parent::class, 'trace'))->setValue($this, $originalTrace);