Problem/Motivation

In FinalExceptionSubscriber I see this code which removes the first backtrace item for output:

        $backtrace = $backtrace_exception->getTrace();
        // First trace is the error itself, already contained in the message.
        // While the second trace is the error source and also contained in the
        // message, the message doesn't contain argument values, so we output it
        // once more in the backtrace.
        array_shift($backtrace);

The problem: The first backtrace item contains a line number which is _not_ present in the message.
The reason is that the file name and line number of a backtrace item is not where the function is defined, but where it is called.

Steps to reproduce

Inject a bug that triggers the exception handler.
Enable full error reporting.

Expected message (example):

InvalidArgumentException: A valid cache entry key is required. Use getAll() to get all table data. in Drupal\views\ViewsData->get() (line 128 of core/modules/views/src/ViewsData.php).

Drupal\views\ViewsData->get() (Line: 311)
Drupal\views\Plugin\views\query\QueryPluginBase->getEntityTableInfo() (Line: 105)

Actual message (example):

InvalidArgumentException: A valid cache entry key is required. Use getAll() to get all table data. in Drupal\views\ViewsData->get() (line 128 of core/modules/views/src/ViewsData.php).

Drupal\views\Plugin\views\query\QueryPluginBase->getEntityTableInfo() (Line: 105)

We see that line number 311 is nowhere to be found in the "actual" part.

Proposed resolution

Don't call array_shift() on the backtrace.

Optionally remove the function name from the message to avoid redundancy.

Check if there are more places like this.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3564356

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:

Comments

donquixote created an issue. See original summary.

donquixote’s picture

Issue summary: View changes

I find these other places with a very simple search:

core/tests/Drupal/Tests/BrowserTestBase.php
673:      array_shift($backtrace);

core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php
224:      array_shift($backtrace);

core/tests/Drupal/TestTools/Extension/Dump/DebugDump.php
164:      array_shift($backtrace);
170:      array_shift($backtrace);

core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php
121:        array_shift($backtrace);

core/lib/Drupal/Core/Utility/Error.php
112:    array_shift($backtrace);
137:      array_shift($backtrace);

core/includes/errors.inc
251:        array_shift($backtrace);

donquixote’s picture

Status: Active » Needs review

Let's see what CI says.

quietone’s picture

Title: Don't remove first backtrace item in FinalExceptionSubscriber (and elsewhere). » Don't remove first backtrace item in FinalExceptionSubscriber (and elsewhere)
Version: 11.0.x-dev » 11.x-dev

Just updating version.

smustgrave’s picture

Status: Needs review » Needs work

This broke some functional tests which may show why this is needed?

Looking at the expected message though isn't it just repeating what's in the error?

donquixote’s picture

The fail is inherent to 11.0.x branch. Changed the base to 11.x now.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.