Skip to content

Commit

Permalink
Friendlier messages, avoiding use of corrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Aug 29, 2023
1 parent 49438eb commit 1a05fa7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion R/outpack_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ orderly_copy_files <- function(..., files, dest, overwrite = TRUE,
file_export(root, id, plan$there, plan$here, dest, overwrite),
not_found_error = function(e) {
if (id %in% root$index$unpacked()) {
## The most likely reason for things to have failed is that
## the user has deleted part of the archive.
name <- outpack_metadata_core(id, root)$name
packet_exists <- file.exists(
file.path(root$path, root$config$core$path_archive, name, id))
reason <- if (packet_exists) "locally modified" else "deleted"
cmd <- sprintf(
'orderly2::orderly_validate_archive("%s", action = "orphan")', id)
cli::cli_abort(
c("Unable to copy files, due to corrupt packet {id}",
c("Unable to copy files, due to {reason} packet {id}",
i = "Consider '{cmd}' to remove this packet from consideration"),
parent = e)
} else if (!as_orderly_search_options(options)$allow_remote) {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-run.R
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ test_that("cope with manually deleted packets, exclude from deps", {
"Failed to run report")
expect_equal(
err$parent$message,
set_names(paste("Unable to copy files, due to corrupt packet", id),
set_names(paste("Unable to copy files, due to deleted packet", id),
""))
cmd <- sprintf('orderly2::orderly_validate_archive("%s", action = "orphan")',
id)
Expand Down Expand Up @@ -1060,7 +1060,7 @@ test_that("cope with corrupted packets, exclude from deps", {
"Failed to run report")
expect_equal(
err$parent$message,
set_names(paste("Unable to copy files, due to corrupt packet", id),
set_names(paste("Unable to copy files, due to locally modified packet", id),
""))
cmd <- sprintf('orderly2::orderly_validate_archive("%s", action = "orphan")',
id)
Expand All @@ -1072,7 +1072,7 @@ test_that("cope with corrupted packets, exclude from deps", {
expect_s3_class(err$parent$parent, "not_found_error")
expect_equal(
err$parent$parent$message,
sprintf("File 'data.rds' in 'data/%s' is corrupt", id), "")
sprintf("File 'data.rds' in 'data/%s' is corrupt", id))
expect_null(err$parent$parent$body)
expect_match(
err$parent$parent$parent$message,
Expand Down

0 comments on commit 1a05fa7

Please sign in to comment.