Skip to content

Commit

Permalink
Add a better error for pin_versions() (#657)
Browse files Browse the repository at this point in the history
* Add logic to trigger better error message

* Update tests

* Update snapshots

* Update NEWS
  • Loading branch information
juliasilge authored Sep 30, 2022
1 parent 2bbadcd commit bb200b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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

0 comments on commit bb200b0

Please sign in to comment.