With https://www.drupal.org/node/2665232 we got line numbers for backtrace information, which was very helpful. I think adding the file name is also important because sometimes the code/line number are not related, meaning sometimes it is showing the code executed on the line of another file. Attaching the patch with the file information.

An example output:

The website encountered an unexpected error. Please try again later.

Exception: Example in Drupal\some_module\Controller\WeekController->content() (line 44 of modules/custom/c4l_lesson_planner/src/Controller/WeekController.php).
call_user_func_array(Array, Array) (in /var/www/example.com/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php on line 128)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (in /var/www/example.com/public_html/core/lib/Drupal/Core/Render/Renderer.php on line 577)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (in /var/www/example.com/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php on line 129)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (in /var/www/example.com/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php on line 102)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (in /var/www/example.com/public_html/vendor/symfony/http-kernel/HttpKernel.php on line 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (in /var/www/example.com/public_html/vendor/symfony/http-kernel/HttpKernel.php on line 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (in /var/www/example.com/public_html/core/lib/Drupal/Core/StackMiddleware/Session.php on line 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (in /var/www/example.com/public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php on line 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (in /var/www/example.com/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php on line 103)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (in /var/www/example.com/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php on line 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (in /var/www/example.com/public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php on line 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (in /var/www/example.com/public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php on line 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (in /var/www/example.com/public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php on line 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (in /var/www/example.com/public_html/core/lib/Drupal/Core/DrupalKernel.php on line 637)
Drupal\Core\DrupalKernel->handle(Object) (in /var/www/example.com/public_html/index.php on line 19)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rballou created an issue. See original summary.

rballou’s picture

dawehner’s picture

Status: Active » Needs review

Ideally we should expand the test coverage

+++ b/core/lib/Drupal/Core/Utility/Error.php
@@ -182,7 +182,11 @@ public static function formatBacktrace(array $backtrace) {
-        $line = " (Line: {$trace['line']})";
+        $line = " (Line: {$trace['line']}";
+        if (isset($trace['file'])) {
+          $line .= ':' . str_replace(DRUPAL_ROOT, '', $trace['file']);
+        }
+        $line .= ")";
       }

IMHO we don't need this replacement of DRUPAL_ROOT, having absolute filepaths doesn't really cause an issue.

Status: Needs review » Needs work

The last submitted patch, 2: 2688615-file-name-in-backtrace.patch, failed testing.

rballou’s picture

Sounds good, new patch attached with the full file path

dawehner’s picture

You have to adapt/expand the existing test coverage for that

rballou’s picture

Here's a new patch with the updated tests

dawehner’s picture

Status: Needs work » Needs review

Setting back to needs review, so the testbot executes it.

The last submitted patch, 5: 2688615-file-name-in-backtrace-2.patch, failed testing.

dawehner’s picture

It would be great to give an example in the issue summary of before and after ... so its easier for people to judge the proposed change.

rballou’s picture

Issue summary: View changes

Added example output to the issue summary.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +DX (Developer Experience)

Thanks a ton!

  • catch committed 0d77fa5 on 8.2.x
    Issue #2688615 by rballou, dawehner: Add the file to Error::...
catch’s picture

Committed 0d77fa5 and pushed to 8.2.x. Thanks!

Leaving RTBC for 8.1.x - this looks fine for a patch release but we're in rc commit freeze at the moment.

alexpott’s picture

+++ b/core/tests/Drupal/Tests/Core/Utility/ErrorTest.php
@@ -89,28 +89,28 @@ public function providerTestFormatBacktrace() {
+    $data[] = array(array($this->createBacktraceItem(NULL, NULL)), "main() (Line: 10:test_file)\n");

I'm not totally convinced about the format Line: NN:FILE. The colon are being used weirdly.

alexpott’s picture

How about we copy PHP and do something like (in FILE on line NN)...

The standard PHP error message looks like this:

Parse error: syntax error, unexpected '$request' (T_VARIABLE) in /Volumes/devdisk/dev/sites/drupal8alt.dev/index.php on line 18
rballou’s picture

I'd support that. I was just trying to roll with what was started in the related issue. Let me know if that's the direction we should head and I can update the patch.

catch’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Reviewed & tested by the community » Needs work

Makes sense to me as well.

I went ahead and reverted the 8.2.x commit so it's just a single patch for both branches again. Moving back up and CNW for that change.

  • catch committed 0e16e16 on 8.2.x
    Revert "Issue #2688615 by rballou, dawehner: Add the file to Error::...
rballou’s picture

New patch with the "in FILE line N" format. I left the parenthesis around that information but that can also easily be removed those are not desired. Thanks

rballou’s picture

Issue summary: View changes

Updated summary

dawehner’s picture

Status: Needs work » Needs review

.

Status: Needs review » Needs work

The last submitted patch, 21: 2688615-file-name-in-backtrace-4.patch, failed testing.

  • catch committed 0d77fa5 on 8.3.x
    Issue #2688615 by rballou, dawehner: Add the file to Error::...
  • catch committed 0e16e16 on 8.3.x
    Revert "Issue #2688615 by rballou, dawehner: Add the file to Error::...

  • catch committed 0d77fa5 on 8.3.x
    Issue #2688615 by rballou, dawehner: Add the file to Error::...
  • catch committed 0e16e16 on 8.3.x
    Revert "Issue #2688615 by rballou, dawehner: Add the file to Error::...

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

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • catch committed 0d77fa5 on 8.4.x
    Issue #2688615 by rballou, dawehner: Add the file to Error::...
  • catch committed 0e16e16 on 8.4.x
    Revert "Issue #2688615 by rballou, dawehner: Add the file to Error::...

  • catch committed 0d77fa5 on 8.4.x
    Issue #2688615 by rballou, dawehner: Add the file to Error::...
  • catch committed 0e16e16 on 8.4.x
    Revert "Issue #2688615 by rballou, dawehner: Add the file to Error::...

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.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.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

geek-merlin’s picture

geek-merlin’s picture

dawehner said in #3:
> IMHO we don't need this replacement of DRUPAL_ROOT, having absolute filepaths doesn't really cause an issue.

We should really put that in again. I have 2 hosters that have ~200 character root paths, which include a build specific hash...

dawehner’s picture

@axel.rutz fair point. Do you mind putting it back in?

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.