Problem/Motivation

See #3382581-16: Add new `EntityBundleExists` constraint, -18 and -19:

While "gracefully returning" sounds good, it also means that the developer who writes a typo like EntityBundleExists: '%paren.target_entity_type_id', they get no feedback!

Because if we don't, we could probably throw an error and tell people something like: %paren found in resolved schema, there is a typo in your schema definition..

Steps to reproduce

Create a config schema definition with a typo in it. Note the absence of a useful error, making for a very painful DX.

Proposed resolution

Add helpful error message! Improved DX 🚀

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

CommentFileSizeAuthor
#5 3392903-2.patch2.52 KBborisson_
#5 interdiff.txt2.48 KBborisson_
#3 3392903.patch2.52 KBborisson_

Issue fork drupal-3392903

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

borisson_’s picture

Status: Postponed » Needs review
Issue tags: +DrupalCon Lille 2023
StatusFileSize
new2.52 KB

Implementation discussed with @Wim Leers yesterday. Patch builds on top of 3382581

wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Config/Schema/TypeResolver.php
    @@ -84,8 +84,17 @@ private static function replaceVariable(string $value, $data) {
    +    $previous_name = null;
    

    s/null/NULL/

  2. +++ b/core/lib/Drupal/Core/Config/Schema/TypeResolver.php
    @@ -84,8 +84,17 @@ private static function replaceVariable(string $value, $data) {
    +        throw new \LogicException('The only valid usages of a config schema with a % in it are %parent, %key, and %type in ' . $value);
    

    \Drupal\Core\Config\TypedConfigManager::replaceVariable() calls these variable values, we should probably do the same here.

  3. +++ b/core/lib/Drupal/Core/Config/Schema/TypeResolver.php
    @@ -84,8 +84,17 @@ private static function replaceVariable(string $value, $data) {
    +        throw new \LogicException('%type can only used when immediatly preceeded by %parent in ' . $value);
    

    Typos 😅

borisson_’s picture

StatusFileSize
new2.48 KB
new2.52 KB
borisson_’s picture

Status: Needs work » Postponed

Was looking at the configuration validation issues, and noticed this should actually be marked as postponed, changing status to match the reality.

wim leers’s picture

#3406487: Consistently use "dynamic type name" and "expression" instead of "variable value" in TypedConfigManager's terminology landed!

@borisson_: Could we add a secondary MR here that does not modify TypeResolver (which does not exist yet, which is why this issue is postponed), but instead modifies TypedConfigManager? We'd have to rebase the EntityBundleExists MR that this is blocked on, but we probably need to rebase it anyway at this point.

wim leers’s picture

Title: [PP-1] Validate inputs of config schema's TypeResolver: only allow %parent, %type and %key » Validate inputs of TypeResolver::resolveExpression(): only allow %parent, %type and %key
Assigned: Unassigned » wim leers
Status: Postponed » Active

#3382581: Add new `EntityBundleExists` constraint landed so this is now unblocked!

wim leers’s picture

Status: Active » Needs review

Transformed #5 into a MR. Now reviewing 🤓

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Needs work
wim leers’s picture

FWIW, this is becoming more important, because other issues are starting to adopt TypeResolver too — for example #3324140: Convert field_storage_config and field_config's form validation logic to validation constraints.

borisson_’s picture

Status: Needs work » Needs review

Fixed the remarks from @Wim Leers. I had to update one existing test: https://git.drupalcode.org/project/drupal/-/merge_requests/6404/diffs?co...

wim leers’s picture

Status: Needs review » Needs work

Looking close, two small pieces of feedback 😊

borisson_’s picture

Fixed the first (variable value) remark, the other one is a bit harder to figure out. It's part of the test coverage we created for #3382581: Add new `EntityBundleExists` constraint, not for this issue.
I don't know how to add the requested test coverage.

wim leers’s picture

@borisson_ You'll want to modify the test logic to not just mock a parent level, but a grandparent level. That way you'd be able to at least test %parent.%parent.entity_type_id, and then there's >1 test case again :)

borisson_’s picture

Status: Needs work » Needs review
Issue tags: +drupalmountaincamp

Fixed the feedback, rerolled on 11.x and added test coverage for %key. I think this is now ready for another round of reviews.

borisson_’s picture

wim leers’s picture

Status: Needs review » Needs work
borisson_’s picture

Status: Needs work » Needs review

Hopefully resolved the new comments.

wim leers’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs issue summary update

Was going to RTBC, then spotted one last small problem. 🫣

Updated the issue summary for you :)

borisson_’s picture

Status: Needs work » Needs review

Applied Wim's latest suggestion, it is indeed more clear like this.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 94e4d4715c to 11.x and fce65ce3aa to 10.3.x. Thanks!

  • alexpott committed fce65ce3 on 10.3.x
    Issue #3392903 by borisson_, Wim Leers, phenaproxima: Validate inputs of...

  • alexpott committed 585650c6 on 11.x
    Issue #3392903 by borisson_, Wim Leers, phenaproxima: Validate inputs of...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.