Expected error being overwritten by last thrown exception
Describe the bug Occasionally when our application throws an exception, the expected error is replaced by a caught exception that is thrown in the error handler.
A basic example of what I'm seeing is that our application will throw
throw new Exception('Cancellation failed. '.$e->getMessage());
which Laravel reports to Sentry. Sentry has the correct error but this is the exception reported to ELK:

However, this exception is caught and ignored in getComposerPackages.

To Reproduce I've been unable to replicate this outside of our environment. I will create an application with our exact versions and try to replicate it.
Expected behavior The correct exception is reported.
I've reproduced this in a container in https://github.com/Nacoma/apm-errors-repro.
Can probably run the container with docker compose up -d and trigger the error by visiting localhost:8082. Following the trace logs with docker compose logs you can see that the caught exception is being sent instead of the other.
The changes I made in https://github.com/Nacoma/apm-errors-repro/blob/6883906b3adfc13894106ce3c3e0a99da94fb5fd/app/Exceptions/Handler.php are the main factor it seems.