esmero / format_strawberryfield

Set of Display formatters, extractors and utils to make Strawberry field data glow
GNU Lesser General Public License v3.0
6 stars 9 forks source link

Getting NOTICE: PHP message: PHP Fatal error: "0" is an invalid render array key during Metadata Display Preview even if Render using Native is not enabled #369

Closed DiegoPino closed 9 months ago

DiegoPino commented 1 year ago

What?

New here. If outputting {{ variable_holding_array }} during preview I get a Fatal error. This is not supposed to happen and looks like a regression/bug to me. Update: Nope. Not really. Related to if/not the Drupal Error Handler is enabled or not. So not a regression, but still something we need to deal with bc I do feel in production we could have cases where people decide to use the normal PHP error handler instead of the built in Drupal one to avoid user facing errors (but also c'mon avoid white screens)

Testing with 1.2.0 and Drupal 9.5.10

DiegoPino commented 1 year ago

Interesting. This happens only when the global error handler is not the Drupal one.

I believe that for "safety" of every Archipelago rendering of Metadata displays should happen around our own error handler. Because there is no way we can know which error handler is in place other than using Drupal's variables / settings maybe what webform module does is the key

function _webform_entity_element_validate_rendering_error_handler($error_level, $message, $filename = NULL, $line = NULL, $context = NULL) {
  // From: http://stackoverflow.com/questions/15461611/php-try-catch-not-catching-all-exceptions
  if (E_RECOVERABLE_ERROR === $error_level) {
    // Allow Drupal to still log the error but convert it to a warning.
    _drupal_error_handler(E_WARNING, $message, $filename, $line, $context);
    throw new ErrorException($message, $error_level, 0, $filename, $line);
  }
  else {
    _drupal_error_handler($error_level, $message, $filename, $line, $context);
  }
}

Basically this error handler here converts any error that is recoverable into a WARNING, which includes E_USER_ERROR