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

Add a better error for pin_versions() #657

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pins (development version)

* Improved error message for `pin_versions()` (#657).

# pins 1.0.3

* The `arrow` package is now suggested, rather than imported (#644, @jonthegeek).
Expand Down
4 changes: 3 additions & 1 deletion R/pin_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ pin_versions <- function(board, name, ..., full = deprecated()) {
lifecycle::deprecate_warn("1.0.0", "pin_versions(full)")
}

if (missing(name) || is.board(name) || name %in% board_list()) {
if (missing(name) && is.board(board)) {
abort("Argument `name` is missing, with no default")
} else if (missing(name) || is.board(name) || name %in% board_list()) {
swap <- board
board <- if (missing(name)) NULL else name
board <- board_get(board)
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/_snaps/pin_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
x <- pin_versions("x", "local")
x <- pin_versions("x", board)

# can't swap arguments with modern api
# can't swap arguments or omit name with modern api

Code
pin_versions(name, board)
Condition
Error in `pin_versions()`:
! Please supply `board` then `name` when working with modern boards

---

Code
pin_versions(board)
Condition
Error in `pin_versions()`:
! Argument `name` is missing, with no default

# `full` is deprecated

Code
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-pin_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ test_that("can use old pin_versions() api", {
})
})

test_that("can't swap arguments with modern api", {
test_that("can't swap arguments or omit name with modern api", {
board <- board_temp()
name <- local_pin(board, 1)
expect_snapshot(pin_versions(name, board), error = TRUE)
expect_snapshot(pin_versions(board), error = TRUE)
})

test_that("`full` is deprecated", {
Expand Down