Problem/Motivation
When catching plugin exceptions it might come in handy to figure out for which plugin ID the exception was thrown.
I didn't check whether all usages of PluginException are in fact in the scope of a plugin ID, but I'm feeling like they might.
Proposed resolution
1. A getPluginId() method already existed in InvalidPluginDefinitionException so I moved it to PluginException alongside the protected var $pluginId.
2. Add a pluginId parameter to PluginException constructor and re-factor every instantiation of this class and its subclasses.
Remaining tasks
1. Is provided by patch in #5
2. Add a pluginId parameter to PluginException constructor and re-factor every instantiation of this class and its subclasses.
API changes
InvalidPluginException class will now requires a plugin id parameter.
Original report by @tstoeckler
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Reroll the patch if it no longer applies. | Instructions | ||
Add steps to reproduce the issue | Novice | Instructions | |
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions |
Comment | File | Size | Author |
---|---|---|---|
#73 | interdiff_69-73.txt | 3.83 KB | sahil.goyal |
#73 | interdiff_68-73.txt | 6.22 KB | sahil.goyal |
#73 | 2121349-73.patch | 20.08 KB | sahil.goyal |
#71 | Screenshot 2023-03-24 at 13.27.24.png | 52.77 KB | ricardofaria |
#69 | 2121349-69.patch | 17.77 KB | amanshukla6158 |
Comments
Comment #1
dawehnerThis is kinda of novice task.
Comment #2
garphy CreditAttribution: garphy commentedComment #3
garphy CreditAttribution: garphy commentedBase PluginException class doesn't define a specific constructor parameter for the pluginId. New instance creation are passed the pluginId via the $code parameter (from Exception base class).
On the other end, PluginNotFoundException and InvalidPluginDefinitionException define a $pluginId constructor parameter which is redundant with $code.
There is less instance creation of those two so it would be more straightforward to drop the specific $pluginId argument and use $code everywhere in an aim to unify those classes (getPluginId() would return $code).
On the other hand, is it the real purpose of the $code argument. Shouldn't we add a $pluginId constructor parameter to the PluginException class and fix all instance creation (and what value give to $code in that case?)
Comment #4
dawehnerYeah indeed we have to expand the exception class or provide one for cases where the plugin ID is known. It is always a better DX if you provide more context.
Comment #5
garphy CreditAttribution: garphy commentedThis is a first attempt.
A getPluginId() method already existed in InvalidPluginDefinitionException so I moved it to PluginException alongside the protected var $pluginId.
Next step (if tests don't already broke at this step) : Add a pluginId parameter to PluginException constructor and re-factor every instantiation of this class and its subclasses.
(put to need reviews to trigger the bot but I don't think it's finished yet)
Comment #6
garphy CreditAttribution: garphy commentedTestbot is happy. Deeper refactoring can take place.
Comment #7
johnennew CreditAttribution: johnennew commentedComment #8
garphy CreditAttribution: garphy commentedI added a plugin_id argument in PluginException and re-factored every instantiation I could find.
Comment #9
jsobiecki CreditAttribution: jsobiecki commentedI'm work on review for a patch.
Comment #11
jsobiecki CreditAttribution: jsobiecki commentedThe patch looks OK for me.
I verified if all execution of PluginException hierarchy constructors:
- InvalidDeriverException
- InvalidPluginDefinitionException
- PluginNotFoundException
For all cases, constructor is updated.
My local phpunit execution complains about incomplete tests, but there are out of scope of this issue. It's related to issue #2299795, so it's different story. I'm still waiting for output from testbot.
Comment #12
jsobiecki CreditAttribution: jsobiecki commentedI got failing tests, I'm investigating that.
Comment #13
jsobiecki CreditAttribution: jsobiecki commentedI found source of problem. One of PluginNotFound exceptions has one argument too much and php complained about type of arguments. I fixed that, and attached patch should hopefully fix the issue.
Comment #14
jsobiecki CreditAttribution: jsobiecki commentedComment #15
mradcliffeI will make this "needs work" when it comes back from test bot.
This should be @todo per documentation standards: https://www.drupal.org/coding-standards/docs#todo
Usually we make a follow-up issue about this.
Can we find a follow-up issue for this that already exists or create a new one.
Comment #16
mradcliffeI'll mark this needs work right now anyway.
Comment #17
garphy CreditAttribution: garphy commentedThere's already an issue so I'm removing the TODO :
#2302805: Have a more specific exception for menu links than generic pluginException (maybe two)
Comment #18
garphy CreditAttribution: garphy commentedComment #19
garphy CreditAttribution: garphy commentedComment #20
garphy CreditAttribution: garphy commentedComment #21
jsobiecki CreditAttribution: jsobiecki commentedLatest changes (patch #18) removes single line of comment (TODO line). I don't see other changes, so it's still look ok for me.
Comment #22
jsobiecki CreditAttribution: jsobiecki commentedComment #25
claudiu.cristeaReplace the docblock with:
What happens when the message is empty? Shouldn't we provide a default generic message?
Empty line between 'namespace' and 'use'.
Just
Exception
, no name spacing while it has been already declared in 'use'.Empty line between description and @param bloc. Missed dot at the end.
Should start with upercase ("The...").
"Optional" should be enclosed in normal/round parentheses. Also there's a end dot missed. When a parameter is optional you should also provide the the default value at the end of description. Example:
(optional) The Exception code. Defaults tp 0.
At the end of the docbloc ass also a reference to
\Exception
:What happens when the message is empty? Shouldn't we provide a default generic message?
Empty line between the 2 methods.
EDIT: Add also an interdiff against the last patch.
Comment #26
rudins CreditAttribution: rudins commentedDid some update based on claudiu suggestions.
Comment #27
claudiu.cristea@rudins, interdiff?
Comment #29
claudiu.cristeaMy bad. It seems that this breaks. Revert it back.a
Comment #30
rudins CreditAttribution: rudins commentedLet's try this one.
Comment #32
mradcliffeLooks like some typos:
Comment #33
nlisgo CreditAttribution: nlisgo commentedAddressed a few errors.
Comment #35
claudiu.cristeaLet's add an interface for this kind of exceptions.
Comment #37
claudiu.cristeaReverted
PluginNotFoundException
message.Comment #38
Mile23Comment #39
cilefen CreditAttribution: cilefen commentedreroll
Comment #40
XanoRe-roll.
Comment #41
XanoSome docs fixes.
PluginExceptionInterface
extendsExceptionInterface
isn't very self-descriptive, especially since they are both in exactly the same namespace. We should try to come up with a slightly better name.Comment #42
jsobiecki CreditAttribution: jsobiecki commentedComment #43
jsobiecki CreditAttribution: jsobiecki as a volunteer commentedHi, I found several places in code, where as id parameter empty string ('') is provided. I'm wondering, if it's valid behaviour and if it should be tolerated, ie:
I'm not sure, but maybe we should provide some sort of failsafe value?
Comment #44
XanoIt's not a problem, so no failsafe is needed, but it is definitely confusing, as in that particular context there simply is no plugin ID.
I think we should keep the old PluginException as it is, and introduce a child exception that should be used for problems with specific plugins, rather than any problem in the plugin system.
Comment #51
quietone CreditAttribution: quietone as a volunteer commentedJust a reroll with an additional change to a new use of the plugin exception in /core/modules/layout_builder/src/SectionComponent.php.
Comment #52
oknateIt looks like there's an additional one in DefaultFactory.php that can be updated.
Comment #53
oknateComment #54
oknateComment #57
quietone CreditAttribution: quietone as a volunteer commentedRerolled
Comment #58
quietone CreditAttribution: quietone as a volunteer commentedThat patch didn't include the new file, PluginExceptionInterface.php. This corrects that and uses sprintf instead of String::format in MenuLinkManager.php.
Comment #59
tim.plunkettThis was opened almost 7 years ago, long before the approach to BC was adopted.
In order to make this change now, we'd have to introduce a new exception class and deprecate the existing one, not change the constructor of the existing one.
Comment #61
quietone CreditAttribution: quietone as a volunteer commentedThis needs work for #59. What should be name of the new exception class?
Comment #67
Nikhil_110 CreditAttribution: Nikhil_110 at Srijan | A Material+ Company commentedRe-roll patch #58 for Drupal 10.x
Comment #68
Akram Khanadded updated patch and try to fixed CCF #67
Comment #69
amanshukla6158 CreditAttribution: amanshukla6158 at OpenSense Labs for DrupalFit commentedfixed phpcs issues.
Comment #71
ricardofaria CreditAttribution: ricardofaria at Cyber-Duck commentedI tested the patch on #69 and it works for 10.1.x-dev.
SS attached.
Comment #72
joachim CreditAttribution: joachim as a volunteer commentedPlease don't post screenshots of applying a patch. It's a waste of diskspace and bandwidth. You can just say it applies. Also, the testbot will say if it doesn't apply.
Also, the patch is failing tests, so at this point it needs work anyway.
Comment #73
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedlatest patchs are failing test, so updating the patch for resolving errors and try to fix these errors, also attaching Interdiff along with.