Skip to content

feat: Give with_pattern() and registry conditions classes - #138

Merged
trevorld merged 1 commit into
mainfrom
feat/condition-classes
Nov 13, 2026
Merged

trevorld merged 1 commit into
mainfrom
feat/condition-classes

Conversation

@trevorld

Copy link
Copy Markdown
Owner

Gives classes to the conditions a caller (e.g. {ggpattern}) may want to catch, re-raise, or muffle.

New condition classes

Class Raised by Fields
gridpattern_area_mismatch with_pattern(): a pattern parameter (or pool) with the wrong number of values per area arg, n_expected, n_given, unit ("area", "grob", or "pool")
gridpattern_pool_mismatch with_pattern(): a pool with areas of more than one grob none
gridpattern_unknown_pattern an unknown pattern name, or a preferred "owner::name" pattern that isn't registered pattern (the name that couldn't be resolved)
gridpattern_ambiguous_pattern a pattern name registered by more than one owner pattern
gridpattern_pattern_conflict register_pattern()'s conflict / masking messages pattern

With delay = TRUE the area check runs at drawing time. The classed error is then the parent of the "couldn't be filled when it was drawn" error. rlang::try_fetch() and expect_error(class =) still find it there; base tryCatch() doesn't.

Other changes

  • A missing suggested package now raises rlang::check_installed()'s error (rlib_error_package_not_found) instead of a custom one. Its offer to install the package is turned off because the patterns check while being drawn. The message wording changes to rlang's.
  • The unknown-pattern error no longer reports the internal abort_unknown_pattern() as its call.
  • The (unreachable) merge_shapes() guard now says "pooled" instead of "grouped".
  • Version bumped to 1.6.0-15 so {ggpattern} can require it.

Message text is otherwise unchanged. The tests check each class and its fields, and the full suite passes locally (2015 tests).

🤖 Generated with Claude Code

* `with_pattern()`'s "one value per area" (and `pool` length) errors have class
  `"gridpattern_area_mismatch"` with fields `arg`, `n_expected`, `n_given`, and `unit`
  (also the parent of the error raised when drawing with `delay = TRUE`).
* Its error for a `pool` with areas of more than one grob has class `"gridpattern_pool_mismatch"`.
* Unknown pattern names (and unregistered preferred patterns) raise `"gridpattern_unknown_pattern"`,
  ambiguous ones `"gridpattern_ambiguous_pattern"`, and `register_pattern()`'s conflict messages
  have class `"gridpattern_pattern_conflict"` (each with field `pattern`).
* A missing suggested package raises `rlang::check_installed()`'s error
  (`"rlib_error_package_not_found"`) without offering to install it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trevorld
trevorld merged commit 89cc7f0 into main Nov 13, 2026
4 checks passed
@trevorld
trevorld deleted the feat/condition-classes branch November 13, 2026 20:37
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.

1 participant