Comments

David_Rothstein’s picture

Here's a patch, as well as a couple patches that allow manual testing (based on #92944: Display generic message and log detailed message when file upload fails due to PHP error where I discovered this).

Go to admin/config/development/logging and configure error messages to display to the screen, then create a node and upload a file. With the patch the error message is displayed; without it it isn't.

David_Rothstein’s picture

Issue tags: +Needs backport to D7

I didn't test Drupal 7 but the code looks similar there so the bug probably occurs too. This might be backportable although we need to think about whether there are any unexpected side effects.

nod_’s picture

haven't tested it but one problem I see is that if the JS expected is some JSON object, printing that will trash everything and while everything should be working on the JS side, it won't. Need to look into it.

David_Rothstein’s picture

When messages are set via drupal_set_message() they aren't printed immediately, rather only when some other code intentionally collects and prints them. So in the case of returning a JSON object (or anything that doesn't use Drupal's standard Ajax system) I think the message will just be held until the next page request and displayed then.

However, that is assuming the message is always set via drupal_set_message(). That's the case in Drupal 7, but Drupal 8 actually does it like this (further down in the function):

      if (\Drupal::hasService('session_manager')) {
        // Message display is dependent on sessions being available.
        drupal_set_message(SafeMarkup::set($message), $class, TRUE);
      }
      else {
        print $message;
      }

I am not really sure what this means or what conditions the else statement would be triggered under, but perhaps this patch should have code to make sure the "print $message" can never happen on an Ajax request.

David_Rothstein’s picture

The print $message code was added in #2317913: Early error handling can result in fatal error (Call to a member function get() on a non-object) and appears to be there for a legitimate reason. So here's a new patch that makes sure that can never be triggered on an Ajax request (in that rare situation, we can continue eating the message and never displaying it, just like happens now).

jhedstrom’s picture

+++ b/core/includes/errors.inc
@@ -173,15 +173,14 @@ function _drupal_log_error($error, $fatal = FALSE) {
+  if ($fatal && $called_from_javascript) {

This will still only display fatal errors?

dawehner’s picture

It would be quite great to have this issue fixed, given how annoying is that, for example, people often do mistakes as the miss notices.

mgifford’s picture

Status: Needs review » Needs work

Patch needs re-roll.

vprocessor’s picture

Assigned: Unassigned » vprocessor
vprocessor’s picture

>>Patch needs re-roll.

Re-rolled, merge conflicts have been fixed

vprocessor’s picture

Assigned: vprocessor » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 10: ajax-display-error-messages-2400477-10.patch, failed testing.

vprocessor’s picture

Assigned: Unassigned » vprocessor
vprocessor’s picture

Code rebuilded, logic saved

vprocessor’s picture

Assigned: vprocessor » Unassigned
Status: Needs work » Needs review
andypost’s picture

Looks good

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs manual testing

There's no confirmation that anyone has manually tested this, instructions are in #1.

andypost’s picture

Is there a steps to reproduce?

Go to admin/config/development/logging and configure error messages to display to the screen, then create a node and upload a file. With the patch the error message is displayed; without it it isn't.

Is that enough?

vprocessor’s picture

Assigned: Unassigned » vprocessor
Status: Needs review » Needs work
vprocessor’s picture

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.

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.

sharma.amitt16’s picture

Status: Needs work » Needs review
StatusFileSize
new2.84 KB

@vprocessor I believe you forgot to unassign this issue. As there is no activity made by you on this from 4 years. So re-rolling the patch for 9.1.x
as I am getting below error while applying patch #14.

curl https://www.drupal.org/files/issues/ajax-display-error-messages-2400477-14.patch | git apply -v                                          amitsharma@MacBook-Pro-2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1790  100  1790    0     0    868      0  0:00:02  0:00:02 --:--:--   868
Checking patch core/includes/errors.inc...
error: while searching for:
    }
  }

  if (\Drupal::hasRequest() && \Drupal::request()->isXmlHttpRequest()) {
diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index fdd9ba58ad..578683e882 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -17,7 +17,7 @@
  * Maps PHP error constants to watchdog severity levels.
  *
  * The error constants are documented at
- * http://php.net/manual/errorfunc.constants.php
+ * http://php.net/manual/errorfunc.constants.php.
  *
  * @ingroup logging_severity_levels
  */
@@ -191,16 +191,15 @@ function _drupal_log_error($error, $fatal = FALSE) {
     }
   }
    if ($fatal) {
      if (error_displayable($error)) {
        // When called from JavaScript, simply output the error message.
        // Should not translate the string to avoid errors producing more errors.
        $response->setContent(SafeMarkup::format('%type: @message in %function (line %line of %file).', $error));
        $response->send();
      }
      exit;
    }
  }
  else {
    // Display the message if the current error reporting level allows this type

error: patch failed: core/includes/errors.inc:187
error: core/includes/errors.inc: patch does not apply

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.

andypost’s picture

Version: 8.9.x-dev » 9.4.x-dev
Status: Needs review » Needs work
Issue tags: +Needs issue summary update

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.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

This has been tagged for steps and issue summary. So moving to PNMI for that info.

acbramley’s picture

StatusFileSize
new24.34 KB

Trying to manually test this one but it's not clear to me how to generate a warning/info/notice message from a file upload.

Generating an error is easy - just make the file directory non-writeable. Error messages are displayed correctly

Given we've been waiting for proper steps to reproduce this since 2016, I wonder if we just close it for now?

mohit_aghera’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I came across this issue while doing the bug-smash triage.

It seems we are missing steps to reproduce since almost 10 years.
Closing this issue for now.

Please reopen again if you feel this is reproducible.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.