rstudio / pins-r

Pin, Discover and Share Resources
https://pins.rstudio.com
Other
301 stars 62 forks source link

Improve error message for problems with URLs #811

Closed juliasilge closed 7 months ago

juliasilge commented 7 months ago

Closes #810

We now see a message like this when we end up in a bad URL situation, such as trying pin_read() on a full path or forgetting a trailing slash for a vanity URL:

library(pins)
board <- board_connect_url(c(
  numbers = "https://colorado.posit.co/rsc/some-nice-numbers"
))
board |> pin_read("numbers")
#> Error in `object_read()`:
#> ! Cannot automatically read pin:
#> • Is your pin specified as a full path? Retrieve it with `pin_download()`
#> • Is your pin specified via a URL that is not a full path, such as a Posit
#>   Connect vanity URL? Remember to include a trailing slash `/`
#> Backtrace:
#>     ▆
#>  1. └─pins::pin_read(board, "numbers")
#>  2.   └─pins:::object_read(meta)
#>  3.     └─cli::cli_abort(...)
#>  4.       └─rlang::abort(...)

Created on 2023-11-17 with reprex v2.0.2

@slodge do you have any feedback on this?

slodge commented 7 months ago

Error message reads much better ... I can't promise I'll read it :)

... but I read the previous one - so there's hope!

I'd guess there was "guessing" the code could have done in the connect_url case - e.g. looking for a file extension, detecting the html response, etc... but I agree that'd be overkill for the case where the user (me!) had typed the url wrong :+1:

Thanks!

juliasilge commented 7 months ago

Most of the basic URL parsing tools out there (urltools::url_parse() and httr::parse_url()) don't really give us directly what we'd need to distinguish between use cases, so I do think it's better to improve the error message rather than try for more guessing.

I appreciate the report a lot -- thanks again! 🙌

github-actions[bot] commented 7 months ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.