[Console] Prevent fatal error when calling Command::getHelper without helperSet#18635
[Console] Prevent fatal error when calling Command::getHelper without helperSet#18635chalasr wants to merge 1 commit intosymfony:masterfrom
Conversation
| public function getHelper($name) | ||
| { | ||
| if (null === $this->helperSet) { | ||
| throw new LogicException(sprintf('Unable to retrieve helper "%s" because there is no HelperSet defined for this command. Did you forget to call %s#setHelperSet()?', $name, get_class($this))); |
There was a problem hiding this comment.
If I'm right, in Symfony we usually use the Class::method syntax instead of Class#method. So %s#setHelperSet() should be %s::setHelperSet() in this error message.
6b99f20 to
50816e2
Compare
|
Could be applied on 2.3 also as bug fix. |
|
👍 ... and I agree about merging it on 2.3. |
| public function getHelper($name) | ||
| { | ||
| if (null === $this->helperSet) { | ||
| throw new LogicException(sprintf('Unable to retrieve helper "%s" because there is no HelperSet defined for this command. Did you forget to call %s::setHelperSet()?', $name, get_class($this))); |
There was a problem hiding this comment.
The message can be confusing as you usually do not set the helper set directly on the command, but configure it for the application instead.
There was a problem hiding this comment.
@xabbuh I simplified it by removing the Did you forget... part, let me know if you think that something like:
Did you forget to set an application for your command via Command::setApplication()? You can also set an HelperSet directly from your command using Command::setHelperSet().
Could be helpful. Thanks
There was a problem hiding this comment.
The first part (setting the application) can as well be related to the command not being registered at the application (which will then set itself on the command).
Maybe something like:
Did you forget to add your command to the application or to set the application on the command using the setApplication() method? You can also set the HelperSet directly using the setHelperSet() method.
c232ecb to
6045a23
Compare
…Helper() without helperSet Use Command::setHelperSet rather than Command#setHelperSet in exception msg Simplify exception message Add DidYouForget to exception msg
6045a23 to
ede4d92
Compare
|
Thank you @chalasr. |
…per without helperSet (chalasr) This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #18635). Discussion ---------- [Console] Prevent fatal error when calling Command::getHelper without helperSet | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18619 | License | MIT | Doc PR | n/a Patch attached to #18619 Commits ------- 31285c2 [Console][#18619] Prevent fatal error when calling Command#getHelper() without helperSet
Patch attached to #18619