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

FR: Error handling when variable is not found: specific error message and class #229

Closed
DanChaltiel opened this issue Oct 24, 2021 · 1 comment · Fixed by #294
Closed
Labels
feature a feature request or enhancement

Comments

@DanChaltiel
Copy link

When using an unknown variable in glue(), the error message can be a little cryptic:

library(glue)
x=5
glue("x={x}")
#> x=5
glue("w={w}")
#> Error in eval(parse(text = text, keep.source = FALSE), envir): object 'w' not found

Created on 2021-10-24 by the reprex package (v2.0.1)

This is most true when glue() is used within a package and even more if the pattern is provided by the package user.
A specific message, such as "Could not find variable 'w' when glueing '{pattern}'", would make it much clearer.

Moreover, as read in the book "Advanced R":

One of the challenges of error handling in R is that most functions generate one of the built-in conditions, which contain only a message and a call. That means that if you want to detect a specific type of error, you can only work with the text of the error message. This is error-prone, not only because the message might change over time, but also because messages can be translated into other languages.

Indeed, dealing with user-defined patterns in glue throwing this error would be a million times easier if this error had a specific error subclass that you would be able to check, as rlang::abort(.subclass=) would do.

Would this be an acceptable feature request?

@hadley
Copy link
Member

hadley commented Jan 25, 2023

We certainly now have the technology to wrap this to make it clear that it's coming from glue.

Similar example is glue::glue("w={w+}")

@hadley hadley added the feature a feature request or enhancement label Jan 25, 2023
hadley added a commit that referenced this issue Jan 26, 2023
hadley added a commit that referenced this issue Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants