Skip to content

Commit

Permalink
Error informatively if no packets found
Browse files Browse the repository at this point in the history
Fixes #144
  • Loading branch information
richfitz committed Jul 4, 2024
1 parent f8282a3 commit 1e0b364
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orderly2
Title: Orderly Next Generation
Version: 1.99.17
Version: 1.99.18
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand Down
17 changes: 17 additions & 0 deletions R/location.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ orderly_location_pull_packet <- function(..., options = NULL, recursive = NULL,
ids <- orderly_search(..., options = options, root = root)
}

if (length(ids) == 0) {
if (options$allow_remote && !options$pull_metadata) {
pull_arg <- gsub(" ", "\u00a0", "options = list(pull_metadata = TRUE)")
hint <- c(i = paste("Did you forget to pull metadata? You can do this",
"by using the argument '{pull_arg}' in the call",
"to 'orderly_location_pull_packet()', or",
"by running 'orderly_location_pull_metadata()'"))
} else {
hint <- NULL
}
cli::cli_abort(
c("No packets found in query, so cannot pull anything",
i = paste("Your query returned no packets, which is probably a mistake",
"so I'm erroring here."),
hint))
}

plan <- location_build_pull_plan(ids, options$locations, recursive, root,
call = environment())

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-location.R
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,21 @@ test_that("can pull a packet from one location to another, using file store", {
})


test_that("can error where a query returns no packets", {
root <- list()
for (name in c("src", "dst")) {
root[[name]] <- create_temporary_root()
}

id <- create_random_packet(root$src)
orderly_location_add("src", "path", list(path = root$src$path),
root = root$dst)
err <- expect_error(
orderly_location_pull_packet(name = "data", root = root$dst),
"No packets found in query, so cannot pull anything")
})


test_that("can pull a packet from one location to another, archive only", {
root <- list()
for (name in c("src", "dst")) {
Expand Down

0 comments on commit 1e0b364

Please sign in to comment.