Skip to content

Review error messages #5557

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

Merged
merged 13 commits into from
Dec 4, 2023
Merged

Review error messages #5557

merged 13 commits into from
Dec 4, 2023

Conversation

olivroy
Copy link
Contributor

@olivroy olivroy commented Dec 2, 2023

Add full stops to error messages + other tweaks. (to adhere to tidyverse style guide)

Also use expect_snapshot() over expect_snapshot_warning() and error_snapshot_error() for consistency. (they are superseded in testthat. It allows to see more clearly what error message the user sees.

I may do a transition to expect_snapshot() in a future PR. For the sake of having a self contained PR, I just reviewed error messages.

olivroy

This comment was marked as resolved.

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

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

Thanks for such a thorough review of all the error messages! The PR looks almost good to me, but if you could have a look at some of the comments that'd be swell.

@olivroy
Copy link
Contributor Author

olivroy commented Dec 4, 2023

I applied your suggestions. Thanks for the prompt review!

On a related note, I was wondering how to make error messages look better:

devtools::load_all("~/rrr-forks/ggplot2/")
#> ℹ Loading ggplot2
#> Warning: le package 'testthat' a été compilé avec la version R 4.3.2
plot <- ggplot(sf::st_polygon(list(matrix(1e3*c(1, 2, 3, 1, 1, 3, 2, 1), ncol = 2)))) +
  geom_sf()
p <- plot +
  scale_x_continuous(
    breaks = c(1000, 2000, 3000),
    labels = function(...) c("A", "B")
  )
ggplot_build(p)
#> Error in `fixup_graticule_labels()`
#> ! `breaks` and `labels` along `x` direction have different lengths.

Created on 2023-12-04 with reprex v2.0.2

Like, how could it show this instead?

#> Error in `scale_x_continuous()`
#> ! `breaks` and `labels` along `x` direction have different lengths.

@olivroy olivroy requested a review from teunbrand December 4, 2023 13:40
@teunbrand
Copy link
Collaborator

I think you could 'lie' and use:

cli::cli_abort({error_message}, call = scale_x$call)

I call this a 'lie' because it is some coord-specific quirck that doesn't let the scale handle breaks/labels as per usual, but the scale is definitely the place where it should be fixed.

@olivroy
Copy link
Contributor Author

olivroy commented Dec 4, 2023

Ok thanks. I may look into this when more PRs are merged.

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

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

Look great, thanks for tackling these messages!

@teunbrand teunbrand merged commit 4a3dd71 into tidyverse:main Dec 4, 2023
@olivroy olivroy deleted the cli branch December 4, 2023 15:19
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