Closed StanAngeloff closed 10 years ago
Or just use the getPrevious()
method instead of only printing the current exception in your own code. This is how exceptions are designed to work throughout PHP, and not all Resque exceptions are caused by previous exceptions anyway, even when such exceptions exist. Including the previous exception's message in the message of the current one obfuscates that there is a previous exception that can be checked, and each step back in the chain has a great deal of useful information that is not transferred upward.
In other words, this seems like it might be useful to implement in your own exception handlers, but should not be implemented in the Exception child class itself.
While your points are valid, they do not take into account first-time experience. There are many cases where your application won't take action based on third-party exceptions. Whether or not the exceptions have been wrapped is out of your control. If an exception occurs in a job, it is my view that php-resque should provide the most accurate and detailed breakdown possible. log4j, for example, always includes the full backtrace. In the context of modern dependency injection-powered applications, exceptions can be caused and wrapped in many different contexts.
Exceptions are designed to be wrappable, e.g., this is why you have $previous
in the Exception
constructor. Yes, you can log it, but at that point you probably have the infrastructure to create your own messaging and scheduling queue as well... which obsoletes Resque altogether.
Revisiting this old PR, I wanted to clarify the original exception is not lost or overridden rather it is enhanced with any previous/nested exceptions.
If anyone is interested, the patch continues to apply cleanly on top of master.
If an exception wraps another, it is impossible to tell what the cause was looking at the outer exception only. If this pull request is merged, when a job fails the full backtrace of all previous exceptions is recorded.
Before:
After: