Overview

#3499947: Managing code components in library made it possible to create new code components in the UI, atop the HTTP API that #3499931: HTTP API for code component config entities provides 🤩 It's really cool to see in action!

Invalid user input will result in the appropriate 422 response with the corresponding validation errors. But the UI does not present those errors:

Proposed resolution

  1. Display detailed errors throughout the code component dialogs, perhaps generic, perhaps only for 422 responses that contain {"errors": {"0": {"details": "…", "source": "…"}, {"1": … }}.
  2. Bonus: use the pattern attribute for providing client-side validation, to make the user immediately aware? 🤓

User interface changes

Validation errors are presented to the user.

Comments

wim leers created an issue. See original summary.

balintbrews’s picture

Title: Add (validation) error handling to AddCodeComponentDialog and friends » Display validation errors in code component dialogs
Issue summary: View changes

Made some edits to better reflect that errors are already handled, but the error details are not exposed.

Besides the 422 error, what other errors can we expect?

Currently sending a machineName that's already taken results in a 500 error, which Wim already explained in a Slack conversation that:

500 you should NEVER see on a live site: it essentially always means “Server-side bug”.

With that said, I don't think we should be concerned about that before we tackle #3503272: JavaScriptComponent config entities should have mutable machineNames, which would mean the client doesn't need to send what is used as the id entity key for the config entity.

wim leers’s picture

Currently sending a machineName that's already taken results in a 500 error, which Wim already explained in a Slack conversation that:

We'll need to change that to return a 409 (conflict).

Besides the 422 error, what other errors can we expect?

No other HTTP status codes; you should only see 409 and 422.


Note: I agree the value is currently limited. But as soon as #3500017: Defining props for code components lands, there'll be even more possibilities for validation errors: props must be named in a particular way, for example (just like machineName in the example above). And the name of a prop must not be used by a slot, and vice versa.

So: the more complete #3499919: [Meta] Plan for in-browser code components becomes, the more valuable this becomes.


For more context:

  1. 🐛 \Drupal\experience_builder\Controller\ApiConfigControllers::post() should generate a 409 for a duplicate entity ID!
  2. the test cases in \Drupal\Tests\experience_builder\Kernel\Config\JavaScriptComponentValidationTest::providerTestEntityShapes() that start with the string 'Invalid: for a sense of what validation errors could occur.
  3. ⚠️Note that this relies almost completely on SDC's metadata validation, which itself is incomplete/inaccurate — for example #3493086: SDC DX does not inform about invalid JSON schemas.
  4. the end-to-end HTTP API test coverage for these config entities — which is nowhere near as complete as I'd like — at \Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent(). I know for sure that the renaming/remapping in \Drupal\experience_builder\Entity\JavaScriptComponent::normalizeForClientSide() is not being respected when generating validation errors, so a validation error for a key the client sent may return a validation error for a different key: in the server-side representation. \Drupal\experience_builder\Controller\ApiConfigControllers should be using ConstraintPropertyPathTranslatorTrait but doesn't yet.

… but none of that is actually a blocker for this issue — this issue can pretend none of those problems exist, and in a future server-side issues we can fix all that — when somebody runs into it :)


Did you see

  1. Bonus: use the pattern attribute for providing client-side validation, to make the user immediately aware? 🤓

?

That'd literally prevent the 422 in the screenshot from ever occurring!

wim leers’s picture

Title: Display validation errors in code component dialogs » Display validation errors in dialogs that create XB config entities (code component, section)
Related issues: +#3504434: ConstraintViolationException: Validation errors exist when creating section

It's possible to run into the same problem for the "section" creation dialog: #3504434: ConstraintViolationException: Validation errors exist when creating section.

wim leers’s picture

Currently sending a machineName that's already taken results in a 500 error […]

Fixed: #3504366: ApiConfigControllers::post() should detect a conflicting ID and throw a 409 exception 😊

So #3.1 is fixed, the rest isn't yet.

(That also now guarantees that 422 responses follow that helpful format — thanks to tightening /openapi.yml.)

kristen pol’s picture

StatusFileSize
new298.19 KB
new461.35 KB

I'm seeing this with latest XB+SDDS.

Added 4 columns with cards in each slot and tried to create a section from that and it gives:

Failed to save section

Error 500: No data provided to evaluate expression ℹ︎␜entity:media:image␝field_media_image␞␟alt

but the alt text exists on each image.

 No data provided to evaluate expression shown in popup

Browser inspect with 4 card section showing images have alt text

wim leers’s picture

wim leers’s picture

FYI: #3514035: Creating multiple components with same label causes error: entity with ID already exists was created for a subset of what this issue is about — specifically the 409 (conflict) case that @balintbrews surfaced in #2.

wim leers’s picture

hooroomoo’s picture

hooroomoo’s picture

Adding related issue here, whoever picks this up should check that issue to see if anything can be re-used for the other dialogs.

hooroomoo’s picture

Title: Display validation errors in dialogs that create XB config entities (code component, section) » Display validation errors in dialogs that create sections

#3520071: Show human readable error messages when creating component fails displays errors for code component creation so renaming the title here

Project: Experience Builder » Drupal Canvas
Version: 0.x-dev » 1.x-dev

Experience Builder has been renamed to Drupal Canvas in preparation for its beta release. You can now track issues on the new project page.

balintbrews’s picture

Component: Theme builder » Page builder
Priority: Critical » Normal