Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular register_theme_element() bug #6162

Open
teunbrand opened this issue Oct 26, 2024 · 0 comments · May be fixed by #6169
Open

Circular register_theme_element() bug #6162

teunbrand opened this issue Oct 26, 2024 · 0 comments · May be fixed by #6169
Labels
bug an unexpected problem or unintended behavior

Comments

@teunbrand
Copy link
Collaborator

teunbrand commented Oct 26, 2024

Accidentally, I found myself in a situation where I defined a theme element with itself as its parent.
I couldn't reprex this bug because it halts execution of rmarkdown::render(), but here are the steps to reproduce:

library(ggplot2)
register_theme_elements(
  foobar = element_rect(),
  element_tree = list(foobar = el_def("element_rect", inherit = "foobar"))
)
calc_element("foobar", theme_get())
#> Error in match.fun(FUN) : node stack overflow
#> Error during wrapup: node stack overflow
#> Error: no more error handlers available (recursive errors?); invoking 'abort' restart

It is fine when I use inherit = "rect" or something that isn't the name of the element itself.
So it seems like defining an element with itself as its parent causes the bug.

This error was complicated to track down and the error message itself wasn't very helpful.
I propose we add a check to register_theme_elements() that throws an error when trying to define new elements that have themselves as parents.

@teunbrand teunbrand added the bug an unexpected problem or unintended behavior label Oct 26, 2024
@teunbrand teunbrand linked a pull request Oct 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant