Overview

This is blocked by #3517966: Failing kernel tests for all ways a component source can fail to render on the server side.

Proposed resolution

End user perspective
Fall back to alternative, hardcoded markup.
Implementation perspective
Detect such a failure at the per-component instance level (see #7 for how) using

and:

  1. use fallback markup instead (test: the tests that #3517966: Failing kernel tests for all ways a component source can fail to render on the server side introduced should now expect this fallback markup instead of an exception)
    🤖👩‍🎨 … can be hardcoded and ugly as hell, because this will unblock the necessary design work — see the implementation plan in the meta issue
  2. log this (test coverage: see \Drupal\Tests\big_pipe\Functional\BigPipeTest::testBigPipe() as a reference for how to test the presence of expected log entries)
  3. out of scope: expose it as structured information for the client#3518201: Server-rendered component instances failing to render should expose the meaningful error to the XB UI in a structured way

User interface changes

Before
After
all components in the tree that can be rendered, are rendered, and

Original report

I ran into a server-side error which I believe happens when rendering a preview in #3485427: PHP warning on image props without examples. The error message gets rendered inside the preview canvas not on the initial load but on the first time the preview gets updated. This is extremely confusing behavior and I needed to use a debugger to understand what was happening.

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

lauriii created an issue. See original summary.

lauriii’s picture

Issue summary: View changes
wim leers’s picture

Component: Page builder » Config management
Category: Task » Bug report
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

We don't need to improve error handling. We need to figure out how this is possible, given:

### 3.1 `SDC` `component`s

#### 3.1.1 Criteria for `SDC` `component`s

For an `SDC` to be compatible/eligible for use in XB, it:
…
- MUST have `example` for each required prop
…

👆 This means it should be impossible for the error in the screenshot to ever occur.

Which SDC did this happen for?

lauriii’s picture

Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce

This is not an issue to fix the specific error. I opened #3485427: PHP warning on image props without examples for that. This issue is to improve the error handling, because I would not expect PHP errors from the small preview iframes to render in the preview canvas. I also would not expect errors to render inside the small preview iframes.

wim leers’s picture

Title: Improve server-side error handling » Component previews should NEVER be able to render PHP errors, should fall back to a meaningful error instead
Category: Bug report » Task
Priority: Major » Normal

Fair. But the title is super vague/misleading then. Fixed.

lauriii’s picture

This is not so much about rendering PHP errors vs not. This was about where and how those errors should be rendered. For example, the error in the issue summary, is not even something that happens as part of the preview request, it happens on the component preview request. We should improve the error handling so that errors that happen during API requests, never end up in the preview.

wim leers’s picture

Issue summary: View changes

#6: Yep, that's how I interpreted #4, and what I captured in the updated issue title? 😅

That kind of super broad exception+error catching is something that I've seen only happen in "Drupal userland" one other time: in https://www.drupal.org/project/acquia_migrate, see:

  1. sort of https://git.drupalcode.org/project/acquia_migrate/-/commit/238a173d454ee...
  2. sort of https://git.drupalcode.org/project/acquia_migrate/-/commit/eb881eb8101bb...
  3. but especially https://git.drupalcode.org/project/acquia_migrate/-/commit/7931c1f843be9...

We should do a combination of both catching \Exception (i.e. ALL exceptions) and using PHP's low-level set_error_handler() in ApiComponentsController and ApiPreviewController (probably actually in the code that they call) — those two combined would be able to achieve what you describe, @lauriii 😊

Issue summary updated with outline of implementation based on your feedback.

WDYT? 😊

wim leers’s picture

Issue summary: View changes
lauriii’s picture

Proposal makes sense. Thank you @wim leers! 💯

wim leers’s picture

Comments 11 through 19 of #3489302: Preview entire page not just content area are AFAICT essentially re-hashing this issue 😅😬

larowlan’s picture

Also FWIW I've seen errors break the whole page when using the auto-save controller and pushing invalid data - because SDC has a twig function to validate the component and that throws a RuntimeError that is uncaught.

I had a workaround in an earlier version of https://git.drupalcode.org/project/experience_builder/-/merge_requests/430 that turned this off so at least one invalid component didn't break the whole preview.

We may need to revive that here

wim leers’s picture

Assigned: Unassigned » larowlan

#11: Curious what you think about the detailed plan I wrote up in #7. What you describe works for SDCs, but won't work for arbitrary component types, whereas #7 would.

wim leers’s picture

Status: Active » Needs review
Issue tags: +Usability
wim leers’s picture

Title: Component previews should NEVER be able to render PHP errors, should fall back to a meaningful error instead » Component previews should NEVER be able to render errors, should fall back to a meaningful error instead
Assigned: larowlan » Unassigned
Issue summary: View changes
Issue tags: +Needs tests, +stable blocker
Related issues: +#3508725: ComponentMetadataRequirementsChecker::check() should validate that the example(s) actually match the JSON schema

Note that if we make this also handle JS errors, that a whole class of "oops, application crashed" problems would be guaranteed to be protected against.

wim leers’s picture

Component: Config management » Component sources
wim leers’s picture

wim leers’s picture

Assigned: Unassigned » larowlan

Still would like @larowlan's input — accidentally unassigned in #15.

wim leers’s picture

Priority: Normal » Critical
wim leers’s picture

Title: Component previews should NEVER be able to render errors, should fall back to a meaningful error instead » Component previews should NEVER be able to render errors, should fall back to a meaningful error instead — for all server-rendered component sources

Updating issue title to convey to everyone this bit from the issue summary:

  1. js: SHOULD NOT be possible to happen for "code components" — but actually can if there's a JS error dependent on the input ⚠️ If this turns out to be too difficult to do as part of this issue, this portion can be descoped to a follow-up issue.

AFAICT solving the intent of this issue for code components can only be achieved by wrapping each code component in some XB-owned wrapper that catches these problems. See my related comment at #3499919-22: [Meta] Plan for in-browser code components.

wim leers’s picture

Title: Component previews should NEVER be able to render errors, should fall back to a meaningful error instead — for all server-rendered component sources » [PP-1] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log + expose)
Assigned: larowlan » Unassigned
Issue summary: View changes
Status: Needs review » Postponed

#21: @effulgentsia is confident about <astro-island>'s ability to handle most of this for us, and is confident we’ll be able to still intercept the error and render a nice fallback of our own design/choosing.

That means this issue can focus solely on the server-side aspects, which basically means making all the failing tests that #3517966: Failing kernel tests for all ways a component source can fail to render on the server side introduced, plus add the necessary infrastructure.

wim leers’s picture

Issue tags: +openapi

Given the additions to /xb/api/layout/… responses, this will need to update openapi.yml.

wim leers’s picture

Title: [PP-1] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log + expose) » [PP-2] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log + expose)
Issue summary: View changes

Reflecting that #3517966: Failing kernel tests for all ways a component source can fail to render on the server side is itself also blocked.

And added more detail about how to imoplement this.

wim leers’s picture

Title: [PP-2] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log + expose) » [PP-2] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log)
Issue tags: -openapi
wim leers’s picture

Issue summary: View changes
nagwani’s picture

Issue tags: +sprint
wim leers’s picture

Title: [PP-2] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log) » [PP-1] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log)
larowlan’s picture

wim leers’s picture

Title: [PP-1] Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log) » Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log)
Status: Postponed » Needs work
wim leers’s picture

Rebased 👍

larowlan’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new89.1 KB
new123.64 KB

Showing it in action 😎

I changed the cta1 prop to be required and this broke an existing component.

I could still update the component props and then it rendered fine again.

larowlan’s picture

Issue tags: -Needs tests
larowlan’s picture

StatusFileSize
new163.04 KB

Log entry

larowlan’s picture

Assigned: larowlan » Unassigned
larowlan’s picture

Assigned: Unassigned » wim leers

Only remaining fail is a known issue in HEAD

wim leers’s picture

Assigned: wim leers » longwave
wim leers’s picture

This MR looks great! I posted some Qs on the MR.

The only things I'm missing:

  1. #7.3, aka set_error_handler() + restore_error_handler(). (I realize now that #3517966: Failing kernel tests for all ways a component source can fail to render on the server side did not add explicit test coverage for that.) But … perhaps that's just not really worth it? Because this MR is catching \Throwable instead of \Exception, which means the actually risky subset of errors is already handled?
  2. I would like to see the ability to render a different fallback based on isPreview: FALSE|TRUE, because we'll need that per [#3517941].

Keeping at Needs review for @longwave's review — but I'm excited this looks so close! 😄

larowlan’s picture

Addressed all the feedback. Left one item open to discuss an alternate approach. I think the current approach is scoped to just our neck of the woods and feel the alternate approach (decorating the renderer) would probably be overreach.

wim leers’s picture

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

I'd like @longwave to do the final review here, but this looks great to me 😊

(Let's also add 2 screenshots to the issue summary, one for a crashing component with isPreview: FALSE, one for isPreview: TRUE.)

larowlan’s picture

Issue summary: View changes
Issue tags: -Needs screenshots
StatusFileSize
new37.92 KB
new72.09 KB

Added screenaroonies

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some questions/feedback.

longwave’s picture

Assigned: longwave » Unassigned
longwave’s picture

Status: Needs work » Reviewed & tested by the community

Fixed all my own feedback except for the plugin ID and the user-facing error message, back to RTBC.

larowlan’s picture

wim leers’s picture

Yep, for the user-facing error message, see the parent meta!

Once designers can see this in action (thanks for the screenshots, Lee!), this is much easier to design for 😊

  • wim leers committed 2b288759 on 0.x
    Issue #3485878 by larowlan, longwave, wim leers, lauriii: Server-...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

HUGE leap forward for XB’s robustness! 🥳

Thank you all for the excellent work on this one! 😊 👏

Status: Fixed » Closed (fixed)

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

effulgentsia’s picture

Issue tags: -sprint