Skip to content

Reduce use of throw {ExceptionType} in favor of WordPress error handling #24

@justlevine

Description

@justlevine

What

We should review the current usage of throw * and (when appropriate) handle the error or return WP_Error objects instead.

Why

To butcher the whole "Exceptions should be exceptional" argument, using Exceptions for control flow is an antipattern (in most places but especially ) in WordPress-land.

While in some cases, throwing may be the optimal way to centralize and "abstract" our error handling, more often it leads to try {} catch {} pollution additional doc requirements, and overall more dx complication - especially in the WordPress crowd.

How

Starting top level (WP/MCP/Core) and working inwards, we review where we can directly return a new WP_Error() (and what try-catches we can remove as a result ). This should allow us to review and remediate things incrementally without worrying about disrupting the existing lifecycle while still help prevent us leaking new exceptions in future commits.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions