Problem/Motivation
\Drupal\views\ViewExecutable::setDisplay() includes a helpful debug() statement if you try to set an invalid display.
However, this can be shown to end-users if a site is misconfigured.
What's more, when format_string() was converted to result in an object, the debug statement now shows it as an object!
Debug:
Drupal\Component\Render\FormattableMarkup Object
(
[arguments:protected] => Array
(
[@display] => block_1
)
[string] => setDisplay() called with invalid display ID "@display".
)
in Drupal\views\ViewExecutable->setDisplay() (line 792 of core/modules/views/src/ViewExecutable.php).
Proposed resolution
Either fix the debug statement, or remove it.
Remaining tasks
Credit http://drupal.org/u/tinny (who was the one who found this)
User interface changes
API changes
Data model changes
Comments
Comment #2
tim.plunkettMentioning that tinny was the one who found this.
Comment #3
shashikant_chauhan commentedComment #4
lendudeI would say, take it out. Printing debug information on a live system feels wrong. Looks like Views is the only place in core where this currently happens outside of tests, so should we maybe take them all out?
Other spots I see:
\Drupal\views\Plugin\views\field\FieldPluginBase::addAdditionalFields\Drupal\views\Plugin\views\style\Opml::render\Drupal\views\Plugin\views\style\Rss::render\Drupal\views\Plugin\views\style\StylePluginBase::renderPatch is just for taking out the one in
\Drupal\views\ViewExecutable::setDisplay()Comment #5
dawehnerCan we maybe use a trigger_error or at least some error logging instead?
Comment #6
edwardchiapetI agree that some sort of error logging would be more helpful than suppressing/not showing the error at all.
Comment #7
dawehnerNeeds work based upon #6 and #5
Comment #8
Anonymous (not verified) commentedI do not know which approach is better. On the one hand, the desire to remove this noise is understandable. On the other hand, if the
defaultdisplay has a similar appearance, then the mistake can really not be noticed. Because default display shows instead of invalid display. In addition,trigger_error()has compatible behavior withdebug().Comment #10
lendudeWell definitely v2 for me.
Just thinking about this, and why do we tolerate an invalid ID in the first place? Fail early, fail hard. This is not something that should ever come up in normal use/through the UI, so it's people using bad code, so lets make sure it fails.
This might be to much of an API change, but throwing an exception makes more sense to me. Lets see if this makes anything else fail.
Comment #11
dawehnerThis code is probably coming from Drupal 6, where exceptions weren't really a thing, given views was compatible with php 4.
On the other hand, its a bit tough for me to judge, whether its okay or not to potentially break sites like that. Currently they render the default display, don't they? I think using trigger_error for a while would be certainly the more safe option.
Comment #13
Anonymous (not verified) commented#10: +1. Exception looks like fair behavior.
But also in Drupal there are other places for which the Exception also makes sense to discuss, but now use a softer behavior too:
So the discussion of correct behavior can be delayed. Therefore, to fix the problem here only with the output of the error - it seems logical.
Hence #11: +1 too :)
And like follow-up we can open issue to think about behavior and other cases per#4.
Comment #14
lendudeYeah, from a BC standpoint the exception is too much for now, just wanted to put it out into the world.
Just re-upping @vaplas' patch from #8 to make the last patch in the issue the one we are discussing. I think we all agree that trigger_error is the soft but right way to go here right? So RTBC then.
Comment #16
Anonymous (not verified) commentedOne line ran away :)
Comment #18
Anonymous (not verified) commentedSorry, Drupal ran too. Now I understand #14.
Comment #19
lendudeBot happy, we happy.
Comment #21
star-szrThe exception vs. error decision is not one I'm comfortable making but the patch looks great to me. Adding credit for @tinny as mentioned in the OP.
Comment #23
Anonymous (not verified) commentedComment #24
catchAgreed on trigger_error() vs. introducing a new exception here, however do we want to make that an E_USER_WARNING instead of a notice, that might help to clean up existing incidences of the bug more so that we can introduce an exception in 9.0.0
Also - should we open a follow-up to introduce the exception?
Comment #25
Anonymous (not verified) commented#19, #21, #24 thanks for review!
#24: Done.
Comment #27
Anonymous (not verified) commentedI forgot to drop the test, in case of incorrect behavior. And clarify the type of error.
It is necessary only for simpletest, and will be deleted with PHPUnit.
Comment #28
Anonymous (not verified) commentedOpps, problem with uploaded files, like #2891911-21: Random fail in Drupal\Tests\locale\Functional\LocaleTranslationUiTest::testStringTranslation. Reupload correct versions.
Comment #29
lendudeNice.
Should we have a follow up to deal with the other debug statements in Views? IMO debug statements should not live in core code and as @dawehner pointed out in #11, this is probably a leftover from D6/PHP4 times, so it could do with an update to more current best practice.
Comment #30
Anonymous (not verified) commentedThank you, @Lendude. Done.
Comment #32
lendudePart of this patch got into #2897009: MediaInterface is missing setName() and getName() so that is why this no longer applies.
Comment #33
lendude#2897009: MediaInterface is missing setName() and getName() got fixed by @webchick, this applies again, so back to RTBC
Comment #36
catchCommitted/pushed to 8.5.x and cherry-picked to 8.4.x. Thanks!