drupal 8 - How do we restrict the user's other than admin to see all the php errors?


We have errors showing up in some pages. These errors must be shown only for admin users.

I changed the "Error message to display" as none. Still the errors are showing up. I copied status-messages.html.twig to my theme and tried to give is_admin. That is giving me error. Any help would be appreciated.

{% block messages %} 
  {% if message_list is not empty %} 
    {{ attach_library('bartik/messages') }} 
    <div class="messages__wrapper layout-container"> 
      {{ parent() }} 
  {% endif %} 
{% endblock messages %} 



Error display should only be enabled on a development copy of the website. Even if you hide errors from displaying for some users, there is a good chance the errors can be accessed somewhere from within developer tools (and can pose a huge security risk.) So, the option to disable error display is not available by default 'per user', because the standard pattern is to:

  1. Disable showing errors on production site (under Configuration > Logging and Errors.) Review error logs to gain insight into failures.
  2. On your local / dev environment, add the following to sites/default/settings.local.php to have error showing enabled in that environment

$config['system.logging']['error_level'] = 'verbose';

This way, when you import your installation into dev from live, error display will be enabled by default without any tinkering. A "set-it and forget it" config.

A good article on the subject, with details on debugging Twig properly can be found at https://www.drupixels.com/blog/enable-drupal-8-debugging-mode-and-error-reporting-local-development.

People are also looking for solutions to the problem: "Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.