What are the steps required to reproduce the bug?
See /core/modules/views/src/Element/View.php
It can be reproduced by opening a page with a View (in a block), deleting the View, or (easier) by adding some extra characters to view name ($element['#name']) in $view = Views::getView($element['#name']); line, to force an error (eg $element['#name'].'XXX').

What behaviour were you expecting?
Normal View output

What happened instead?
You get an error: Fatal error: Unsupported operand types in ...../core/modules/views/src/Element/View.php on line 49
This is could be more helpful.

Solution
Test for null return in $view and add a message like 'drupal_set_message(t('View '.$element['#name'].', used on this page, is missing.'), 'error');', and return.
(see patch)

Issue fork drupal-2868258

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jons created an issue. See original summary.

dawehner’s picture

+++ b/core/modules/views/src/Element/View.php
@@ -41,6 +41,10 @@ public static function preRenderViewElement($element) {
       $view = Views::getView($element['#name']);
+      if (is_null($view)) {
+        drupal_set_message(t('View '.$element['#name'].', used on this page, is missing.'), 'error');
+        return;
+      }

I'm wondering whether it would be better to actually throw an exception ...

Lendude’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Active » Needs review
FileSize
1.96 KB

Yeah throwing an exception makes sense to me. So maybe something like this?

dawehner’s picture

  1. +++ b/core/modules/views/src/Element/MissingDataException.php
    @@ -0,0 +1,8 @@
    +class MissingDataException extends \Exception {}
    

    "Data" always sounds super generic / without any meaning

  2. +++ b/core/modules/views/tests/src/Kernel/Element/ViewElementTest.php
    @@ -0,0 +1,28 @@
    +  /**
    +   * Tests that an exception is thrown when an invalid View is passed.
    +   */
    +  public function testInvalidView() {
    +    $renderer = $this->container->get('renderer');
    +    $render_element = [
    +      '#type' => 'view',
    +      '#name' => 'invalid_view_name',
    +      '#embed' => FALSE,
    +    ];
    +    $this->setExpectedException(MissingDataException::class);
    +    $renderer->renderRoot($render_element);
    

    Nice test

Lendude’s picture

Ah yes 'naming things' :)

This any better?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/views/src/Element/View.php
@@ -41,6 +41,9 @@ public static function preRenderViewElement($element) {
+      if (!$view) {
+        throw new InvalidViewException('Invalid View name given.');
+      }

How about including the invalid name in the exception? Would seem helpful - no?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jonathanshaw’s picture

Issue tags: +Needs reroll, +Novice

This one should be really really easy to fix :)

xjm’s picture

Priority: Normal » Major
Status: Needs review » Needs work

Normally, adding a new exception would be a minor-only change. However, given that there is currently a fatal error in HEAD, a new exception is not any more disruptive than that.

Also, given that this causes a WSOD and has steps to reproduce via the user interface, it can be considered major, and is potentially eligible for backport to 8.9.x still for that reason.

An updated patch for #7 and the reroll can also be tested against 9.2.x and 9.1.x if it applies there as well. Otherwise, we can create separate patches.

Thank you!

joegraduate’s picture

Assigned: Unassigned » joegraduate

Going to work on a reroll/merge request and try to incorporate the suggestion from #7.

joegraduate’s picture

This is a re-roll of #5 that incorporates the suggestion in #7. This should apply cleanly to 8.9.x, 9.1.x, and 9.2.x.

joegraduate’s picture

joegraduate’s picture

Assigned: joegraduate » Unassigned
Issue tags: +Bug Smash Initiative, +NorthAmerica2021

Created merge request from #17 to make tugboat live preview available. This should be ready for review/testing.

Status: Needs review » Needs work

The last submitted patch, 17: 2868258-17.patch, failed testing. View results

joegraduate’s picture

Assigned: Unassigned » joegraduate
joegraduate’s picture

Updated patch with latest changes in MR branch:
- Fixed template literal in exception message.
- Replaced deprecated test method.
- Moved exception to Drupal\views\Exception namespace.
- Moved new test into existing ViewElementTest kernel test class.

Tests should pass and this should really be ready for review now.

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community
Jons’s picture

thanks all!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: 2868258-22.patch, failed testing. View results

Lendude’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated fail

larowlan’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/views/src/Exception/InvalidViewException.php
@@ -0,0 +1,8 @@
+ * Exception thrown when an element misses a valid name value.

I think the description here has too much knowledge of when it is thrown. Which would prevent us from reusing this exception elsewhere.

Suggest that we rename the class to ViewRenderElementException and make the the docblock say

'Defines an exception for an invalid View render element' or similar

Then we can re-use this exception later for other uses cases such as when the display name is wrong or the arguments.

Thoughts?

I don't agree with this being a major bug, so dropping the priority, its a developer nuisance more than anything - I would even go close to marking it as minor.

joegraduate’s picture

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community

RTBC if bot agrees.

larowlan’s picture

Version: 8.9.x-dev » 9.1.x-dev
Priority: Normal » Major
Status: Reviewed & tested by the community » Fixed

Revisiting earlier comments I see that xjm classed this as major, so re-instating that.

On that basis this qualifies for backport, but I think the ship has sailed for 8.9.

Committed 1ab0f48 and pushed to 9.3.x. Thanks!

Backported to 9.2 and 9.1

Thanks everyone involved

  • larowlan committed a4cf724 on 9.1.x
    Issue #2868258 by joegraduate, Lendude, Jons, dawehner, alexpott,...
  • larowlan committed 7b54766 on 9.2.x
    Issue #2868258 by joegraduate, Lendude, Jons, dawehner, alexpott,...
  • larowlan committed 1ab0f48 on 9.3.x
    Issue #2868258 by joegraduate, Lendude, Jons, dawehner, alexpott,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.