getConstraints() is typed array but may return null

Created on 2 August 2023, 11 months ago
Updated 22 August 2023, 10 months ago

Problem/Motivation

When using the module on an actual dev instance, the ConfigSchemaValidatability::getConstraints() method may return NULL, causing an error like:

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

TypeError: Drupal\config_inspector\ConfigSchemaValidatability::getConstraints(): Return value must be of type array, null returned in Drupal\config_inspector\ConfigSchemaValidatability->getConstraints() (line 63 of modules/contrib/config_inspector/src/ConfigSchemaValidatability.php).
Drupal\config_inspector\Controller\ConfigInspectorController->formatTree(Object, Object) (Line: 273)
Drupal\config_inspector\Controller\ConfigInspectorController->getTree('core.entity_view_display.node.article.default')

Steps to reproduce

  • Install standard profile and config_inspector.
  • Examine /admin/reports/config-inspector/core.entity_view_display.node.article.default/tree

Proposed resolution

Default to return an empty array with the property path does not match an existing constraint:

Replace:

  public function getConstraints(string $property_path): array {
    return $this->constraints[$property_path];
  }

by

  public function getConstraints(string $property_path): array {
    return $this->constraints[$property_path] ?? [];
  }

Remaining tasks

Ensure we do not need to dig further for a root cause.

User interface changes

Replace exception page by actual results.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Closed: duplicate

Version

2.1

Component

Code

Created by

🇫🇷France fgm Paris, France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024