-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Better exception messages #1226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Previously this was overriding Exception::__toString(). Now setting with the fault code directly.
@nikic 💯 |
This will break any pre-7 tool that tried to look for PHP error messages, and also will make PHP exception messages non-machine-detectable as they won't have neither common prefix nor even common pattern. I don't think this is such a good idea. 👎 |
To make exceptions easily detectable, you could prepend But I don't see why this would make looking for PHP errors harder, just look for |
That will only affect people who refuse to have a top level try/catch block. And who also refuse to use the set_exception_handler to handle uncaught exceptions. TazeTSchnitzel wrote:
+1 |
Even though this wasn't noted in advance during the RFC discussion, closing all "bugs" opened by people confused with the error message is not sustainable - not to mention bad for the users. We should update the error messages and avoid confusion in the first place. 👍 |
I don't see any reason why current message is unsuitable for humans it - reads just fine and the advantage in new way is minimal, while breakage of the tools is substantial. I think dismissing this breakage by saying "tools can be updated" is very nearsighted, and not providing any means for automatic detection of errors is even worse. |
Depends which message you mean. Shortening the exception message may have less benefit, but given that errors produce EngineException now, they need to show up as such. |
This implements a reduced variant of php#1226 with just the following change: -Fatal error: Uncaught exception 'EngineException' with message 'Call to private method foo::bar() from context ''' in %s:%d +Fatal error: Uncaught EngineException: Call to private method foo::bar() from context '' in %s:%d The '' wrapper around messages is very weird if the exception message itself contains ''. Futhermore having the message wrapped in '' doesn't work for the "and defined" suffix of TypeExceptions.
This implements a reduced variant of php#1226 with just the following change: -Fatal error: Uncaught exception 'EngineException' with message 'Call to private method foo::bar() from context ''' in %s:%d +Fatal error: Uncaught EngineException: Call to private method foo::bar() from context '' in %s:%d The '' wrapper around messages is very weird if the exception message itself contains ''. Futhermore having the message wrapped in '' doesn't work for the "and defined" suffix of TypeExceptions.
Closing as I don't plan to further pursue this. |
The fact that engine exceptions currently display as normal fatal errors is causing a lot of confusion, we will need to switch this to proper exception messages before the release. This PR cleans up the current exception messages to make it feasible to use them for engine exceptions as well.
Old message:
New message:
Fallout: The error message for an "uncaught exception" is no longer based on
__toString
. Instead a canonical representation is always used.Internal changes: The error callback now accepts two additional arguments: Firstly, the error type string (like
Fatal error
orUnexpectedValueException
), which can now be changed independently of the error type. Secondly "additional information" which is to be displayed after the message, file and line information. This is used for exceptions to display the stack trace and "next" exceptions.