Skip to content

Introduce sniff to avoid doing_it_wrong usage of register_block_type#347

Merged
kadamwhite merged 1 commit into
mainfrom
register_block_type-sniff
Jul 7, 2026
Merged

Introduce sniff to avoid doing_it_wrong usage of register_block_type#347
kadamwhite merged 1 commit into
mainfrom
register_block_type-sniff

Conversation

@kadamwhite

Copy link
Copy Markdown
Collaborator

register_block_type internally delegates to register_block_type_from_metadata if a readable file path is passed, but if the file does not exist (usually from not having run a build) it throws a confusing _doing_it_wrong message.

We should be using register_block_type_from_metadata directly whenever we are not passing the name of a block as the first argument, since this can lead to wasted debugging time if the error is not understood correctly.

This sniff attempts to put in place some heuristic detection for path-y first arguments passed to register_block_type, to catch this in PRs / CI.

register_block_type internally delegates to register_block_type_from_metadata
if a readable file path is passed, but if the file does not exist (usually
from not having run a build) it throws a confusing doing_it_wrong message.

We should be using register_block_type_from_metadata directly whenever we
are not passing the name of a block as the first argument, since this can
lead to wasted debugging time if the error is not understood correctly.

This sniff attempts to put in place some heuristic detection for path-y
first arguments passed to register_block_type, to catch this in PRs / CI.
@kadamwhite

Copy link
Copy Markdown
Collaborator Author

Tagging a few of you for feedback on whether this feels worth adding to our standard. It's something that's been a slight footgun even after trying to add agent instructions to support using the metadata version, and I'd like to be able to flag it at the PR stage automatically, without wasting human cycles on it — but it's technically already covered by a _doing_it_wrong, assuming the developer is monitoring logs for those properly.

@roborourke roborourke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a simple fix and if it avoids a common problem then it gets my vote.

@kadamwhite kadamwhite merged commit 0fdff4e into main Jul 7, 2026
3 checks passed
@kadamwhite kadamwhite deleted the register_block_type-sniff branch July 7, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants