Skip to content

Fix error handling when pattern creation fails - #85117

Open
elphizu wants to merge 1 commit into
WordPress:trunkfrom
elphizu:fix/pattern-creation-error-handling
Open

elphizu wants to merge 1 commit into
WordPress:trunkfrom
elphizu:fix/pattern-creation-error-handling

Conversation

@elphizu

@elphizu elphizu commented Oct 19, 2026

Copy link
Copy Markdown

What?

Closes #85089.

Display the original REST API error when pattern creation fails.

Why?

A failed pattern save currently returns undefined, which is passed to the success callback. This causes a JavaScript error about wp_pattern_sync_status, hiding the server’s error message.

How?

Pass { throwOnError: true } to saveEntityRecord in createPattern, allowing the modal’s existing error handler to display the original error.

Testing Instructions

  1. Add this code to a temporary must-use plugin:
    <?php
    add_filter(
        'rest_pre_insert_wp_block',
        function () {
            return new WP_Error(
                'pattern_creation_failed',
                'Pattern creation was blocked for testing.',
                array( 'status' => 400 )
            );
        },
        10,
        0
    );
  2. Open a post or page and insert a Paragraph block.
  3. Open the block options menu and select Create pattern.
  4. Enter a name and submit.
  5. Confirm the snackbar displays “Pattern creation was blocked for testing.” instead of a JavaScript error.
  6. Remove the temporary plugin and confirm pattern creation succeeds.

Use of AI Tools

OpenAI Codex was used to investigate the issue, PR Description.

@github-actions github-actions Bot added the [Package] Patterns /packages/patterns label Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

👋 Welcome

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @elphizu! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

🎉 Props

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @kraftner.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: kraftner.

Co-authored-by: elphizu <suryakantupadhyay@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Oct 19, 2026
@elphizu
elphizu marked this pull request as ready for review October 19, 2026 16:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Patterns /packages/patterns

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unclear error handling on failed pattern creation

1 participant