Problem/Motivation

All of us know the nice "the website encounted an error" message during development. Sadly by default errors aren't shown, so you don't see anything here.

Proposed resolution

One nice little improvement could be to add a link to the error settings page, so you can change it easily.

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

That link would then be presented to all end users… which I don't think we want.


The main problem is that many people who are actively working on Drupal 8 core are unaware of the extra step they have to take when installing Drupal 8 (the enabling of settings.local.php). Despite the change notice (https://www.drupal.org/node/2259531).

How can we make people who are helping Drupal 8 get ready to be more aware of this? I wonder if we can do something like:

  1. detect if the site is running on localhost ($_SERVER['SERVER_ADDR'] === '127.0.0.1')
  2. detect if the site is a git checkout (file_exists(DRUPAL_ROOT . '/.git' directory
  3. detect if the current user is the root user ($user->id() == 1
  4. if all of the above are true, show a message like "You may want to enable development mode [etc. etc.]", perhaps linking to a handbook page.
dawehner’s picture

Well, you could guess that developers on custom sites might forget that step as well, not doing something here is a big pain in the ass.
Using a git checkout will probably not work, given how many shops use git as a deployment tool (don't say that this is a good idea at all)

Using localhost seems to be the most straightforward way, what do you think?

Wim Leers’s picture

if (localhost && uid == 1) works for me.

tim.plunkett’s picture

Version: 8.x-dev » 8.0.x-dev
dawehner’s picture

FileSize
1.15 KB

I would rather go with || tbh.

dawehner’s picture

Status: Active » Needs review

.

Status: Needs review » Needs work

The last submitted patch, 5: 2313059.patch, failed testing.

Status: Needs work » Needs review

dawehner queued 5: 2313059.patch for re-testing.

vijaycs85’s picture

I would rather go with || tbh.

+1

+++ b/core/lib/Drupal/Core/Controller/ExceptionController.php
@@ -321,6 +321,14 @@ public function on500Html(FlattenException $exception, Request $request) {
+      $content .= t('In order to see the error message try to enable display errors under "logging and errors" on the admin section or enable it via a settings.local.php, see settings.php.');

$this->t

dawehner’s picture

Here is a quick reroll. I still think this could be a massive improvement of some DX.

Status: Needs review » Needs work

The last submitted patch, 10: 2313059-10.patch, failed testing.

Wim Leers’s picture

  1. +++ b/core/includes/errors.inc
    @@ -246,6 +246,13 @@ function _drupal_log_error($error, $fatal = FALSE) {
    +      if ((\Drupal::hasRequest() && array_intersect(['127.0.0.1', '::1', '::1'], \Drupal::request()->getClientIps())) || (\Drupal::hasService('current_user') && \Drupal::service('current_user')->accountInitialized() && \Drupal::service('current_user')->id() == 1)) {
    

    Isn't '::1' in there twice?

  2. +++ b/core/lib/Drupal/Core/Session/AccountProxyInterface.php
    @@ -48,4 +48,11 @@ public function getAccount();
    +  public function accountInitialized();
    

    This method is not implemented?

dawehner’s picture

Status: Needs work » Needs review
FileSize
4.38 KB
2.68 KB

Sure, there we go.

Status: Needs review » Needs work

The last submitted patch, 13: 2313059-13.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
4.85 KB
483 bytes

Let's see, this could help quite a bit.

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.

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

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.

wturrell’s picture

Rerolled patch on 8.3.x (and about to do some more work on it)

Status: Needs review » Needs work

The last submitted patch, 19: 2313059-19.patch, failed testing.

wturrell’s picture

Re: the failing test:

$subscriber = new DefaultExceptionSubscriber($config_factory);

Our patch means this now needs two parameters. The second is:

* @param \Drupal\Core\Session\AccountProxyInterface $user

*   The account proxy.

Not clear:
- what correct way is to generate user for tests (docs link welcome)
- if it matters which type of user for this one

wturrell’s picture

Changes:

- use PHP filter to check against full IPv4 private range, not just 127.0.0.1 (struggling to find IPv6 equivalent)
- move ip address check to separate function and generally try to make that conditional easier to follow
- "In order to see the error" text was being shown even when they could already see it, fix this
- improve wording of the message
- coding style/standards

(Test will still fail, see #21, so skipping Testbot)

nikunjkotecha’s picture

Status: Needs work » Needs review
FileSize
5.56 KB
873 bytes

Re-rolled patch from #22, removed code from contrib directory. If we want we should add a PHPUnit test case but not a contrib module.

Status: Needs review » Needs work

The last submitted patch, 23: 2313059-23.patch, failed testing.

nikunjkotecha’s picture

Status: Needs work » Needs review
FileSize
6.95 KB
1.39 KB

Fixed issue with failing tests.

dawehner’s picture

  1. +++ b/core/includes/errors.inc
    @@ -286,6 +301,21 @@ function _drupal_log_error($error, $fatal = FALSE) {
    +function _is_private_ip() {
    
    +++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php
    @@ -118,6 +129,14 @@ protected function onHtml(GetResponseForExceptionEvent $event) {
    +    if (array_intersect(['127.0.0.1', '::1'], $event->getRequest()->getClientIps()) || ($this->user->accountInitialized() && $this->user->id() == 1)) {
    

    Can't this use this helper method? At least the same code should be used.

  2. +++ b/core/includes/errors.inc
    @@ -286,6 +301,21 @@ function _drupal_log_error($error, $fatal = FALSE) {
    +         or $ip === '::1';
    

    Note: We don't use "or" but rather ||

wturrell’s picture

@dawehner Ah sorry, I hadn't spotted there was more than one check...

nikunjkotecha’s picture

re-roll with fixes for comments in #26

nikunjkotecha’s picture

wturrell’s picture

@nikunjkotecha:

You've kept the translation in on /DefaultExceptionSubscriber.php, but there's a message in errors.inc saying it's not used because it could create further errors.
Also, in #22, I reworded the message text slightly and wrapped it in a conditional to check that error display was actually turned off - i.e. pointless telling people how to view an error they can already see.

I'd just started working on the patch again when you posted #28, but feel free to do those changes if you like. (Thanks.)

nikunjkotecha’s picture

@wturrell I'm already using your patch in #22 as base :), I saw your comment but I had already started and was waiting for the tests to finish in local before uploading. Just having enough free time today :)

Status: Needs review » Needs work

The last submitted patch, 28: 2313059-28.patch, failed testing.

nikunjkotecha’s picture

submitting for re-test, output on dispatcher is not really helpful

nikunjkotecha’s picture

Status: Needs work » Needs review
wturrell’s picture

No, I realise you used #22. What I mean is there are several changes - besides _is_private_ip(), which you've done – in errors.inc than need to be replicated in DefaultExceptionSubscriber.php:

- it doesn't use a string translation because, depending on what's broken, that might produce a further error whilst trying to print the error
- I've changed the message text in errors.inc slightly from what it was before
- I added an if (!error_displayable($error) conditional

(BTW, that problem with your first test run was a random Testbot failure – it lost a connection.)

The last submitted patch, 22: 2313059-22.patch, failed testing.

dawehner’s picture

- it doesn't use a string translation because, depending on what's broken, that might produce a further error whilst trying to print the error

+1000 for that.

nikunjkotecha’s picture

* Removed use of $this->t() in DefaultExceptionSubscriber
* Refactored code a bit
* Copied message from errors.inc to DefaultExceptionSubscriber
* Added interdiff with 22 as base

Status: Needs review » Needs work

The last submitted patch, 38: 2313059-38.patch, failed testing.

nikunjkotecha’s picture

Added a condition to avoid issues with the call to \Drupal::request()->getClientIps() in _is_private_ip()

swarad07’s picture

Tested the patch. Applies cleanly and addresses the concerns in #35. Would be a welcome addition to the DX.

cilefen’s picture

Title: Adapt the "website encounted an error" message » Add a link to the error settings form on "website encounted an error" message
Version: 8.3.x-dev » 8.4.x-dev

8.3.x is in RC.

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.

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.

smustgrave’s picture

Category: Task » Feature request
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests, +Needs change record

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.

This seems more like a feature request then task

Tagging for tests as the new message is currently not checked.
Also tagging for a change record as we are changing an existing service.

1.

-  public function __construct(ConfigFactoryInterface $config_factory) {
+  public function __construct(ConfigFactoryInterface $config_factory, AccountProxyInterface $user) {
     $this->configFactory = $config_factory;
+    $this->user = $user;
   }

personally I think think $user should default to NULL and a trigger should be added that it will be required in D11

2.

+function _is_private_ip() {
+  // If it is not on screen and end user is not checking the message, there is
+  // no point showing the way to enable details.
+  if (!\Drupal::hasRequest()) {
+    return FALSE;
+  }

This will need to be typehinted as a new function

3.

+  public function accountInitialized() {
+    return isset($this->account);
+  }

same

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.