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
Introduce the usage of Module user-displayable exceptions to handle module errors (part 2) #14239
Introduce the usage of Module user-displayable exceptions to handle module errors (part 2) #14239
Conversation
ec0216f
to
16c0b01
Compare
* If an exception that implements this ModuleErrorInterface | ||
* is thrown, its message will be displayed to the end-user | ||
*/ | ||
interface ModuleErrorInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering is it ok to have an empty interface? I don't mind it's just I wasn't sure it was possible
I had thought of a single getErrorMessage
method which would allow to "customize" the exception message a bit (the simplest implementation being to simply return the exception message). This would allow to separate the exception message and the error message which might be different:
- exception message => technical message with (potentially) sensitive info (db infos, path infos, ...)
- error message => user message more "feature oriented" and safe to display
Besides by using ModuleErrorInterface
you restrict its use to module only, maybe we could call it FlashErrorInterface
which would allow us to use it with core exceptions as well this could simplify our internal getErrorMessages
methods (yet it doesn't make this PR more complicated), wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally it should extend Throwable, then it wouldn't be empty. But it's not possible. It's just a marker interface so that you have more flexibility to create your own exceptions in this specific case.
From a DX standpoint, it's easier to use the exception message. Regarding FlashErrorInterface
it could be integrated in the core later and be made a parent to this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally it should extend Throwable, then it wouldn't be empty. But it's not possible. It's just a marker interface so that you have more flexibility to create your own exceptions in this specific case.
From a DX standpoint, it's easier to use the exception message. Regarding FlashErrorInterface
it could be integrated in the core later and be made a parent to this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok let's do that for now then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @matks
I fixed the empty demo module, QA can proceed 🚀 |
Thank you for review and QA 🎉 |
How to test
Attached is a demonstration module.
module_for_pr_hook_error.zip
If you install it and test this PR,
PR notes
Background
This PR solves 2 issues:
\Exception
because we consider our duty to handle all exception paths and make sure we display the right error message for each, however we cannot guarantee Modules will do the same. So we catch\Exception
in order to avoid the "blank page" behavior.This change is