diff --git a/R/DataMart.R b/R/DataMart.R index 6cb7bf0..85776eb 100644 --- a/R/DataMart.R +++ b/R/DataMart.R @@ -31,7 +31,7 @@ QFileExists <- function(filename, show.warning = TRUE, company.token = NA, docum if (is.null(res$status_code) || res$status_code != 200) { if (show.warning) - warning("File not found.") + warning("This file may not exist in the Displayr Cloud Drive or you may not have permission to access it.") return (FALSE) } else @@ -92,7 +92,7 @@ QFileOpen <- function(filename, open = "r", blocking = TRUE, if (inherits(con, "condition")) { problem <- conditionMessage(con) if (problem == "HTTP error 404.") - problem <- "file not found" + problem <- "This file may not exist in the Displayr Cloud Drive or you may not have permission to access it." stopBadRequest(con, paste0("Could not open ", filename, ": ", problem)) } @@ -224,10 +224,7 @@ QLoadData <- function(filename, company.token = NA, document.token = NA,...) else if (res$status_code != 200) { if (!QFileExists(filename, show.warning = FALSE)) - StopForUserError( - "The data file '", filename, "' does not exist in the Displayr cloud drive. ", - "Ensure that the data file is in the Displayr cloud drive and its name has been correctly specified." - ) + StopForUserError("This file '", filename, "' may not exist in the Displayr Cloud Drive or you may not have permission to access it.") else stopBadRequest(res, msg) } @@ -345,14 +342,12 @@ QSaveData <- function(object, filename, compression.file.size.threshold = NULL, has.errored <- inherits(res, "try-error") if (!has.errored && res$status_code == 413) # 413 comes from IIS when we violate its web.config limits - { stopBadRequest(res, "Could not write to Displayr Cloud Drive. Data to write is too large.") - } - else if (!has.errored && res$status_code == 422) + else if (!has.errored && res$status_code == 404) { stop("QSaveData has encountered an unknown error. ", - "422: The file could not properly be saved. ", - "The likely cause was an incorrect path preceding the filename.") + "404: The file could not properly be saved. ", + "The likely cause was an incorrect path preceding the filename, or insufficient access to the file path.") } else if (has.errored || res$status_code != 200) { @@ -407,7 +402,7 @@ QDeleteFiles <- function(filenames, company.token = getCompanySecret(), document if (inherits(res, "try-error") || res$status_code != 200) { warning("Encountered an error deleting the following files: ", filenames.string) - stopBadRequest(res, paste0("Could not delete files: ", filenames.string)) + stopBadRequest(res, paste0("Could not delete files: ", filenames.string, ". These files may not exist in the Displayr Cloud Drive or you may not have permission to access them.")) } msg <- paste0("Successfully deleted files: ", filenames.string) message(msg) diff --git a/tests/testthat/test-datamart.R b/tests/testthat/test-datamart.R index 9e72e4d..b8bdaf6 100644 --- a/tests/testthat/test-datamart.R +++ b/tests/testthat/test-datamart.R @@ -46,15 +46,15 @@ test_that("Save/Load Data: bad cases", { # Not-existent file bad_name <- "anamethatdoesnotexistfortesting" - QFileExists(bad_name) |> expect_false() |> expect_warning("File not found") - QLoadData(bad_name) |> expect_error(paste0("The data file ", sQuote(bad_name, q = FALSE), " does not exist")) + QFileExists(bad_name) |> expect_false() |> expect_warning("may not exist in the Displayr Cloud Drive or you may not have permission") + QLoadData(bad_name) |> expect_error("may not exist in the Displayr Cloud Drive or you may not have permission") # Invalid filetypes # - note that we don't have tests for Content-Types QSaveData(mtcars, "mtcars.notrdsorcsv") |> expect_error("Invalid file type specified") - # 422 Error + # 404 Error mockedPOST <- function() { - list(status_code = 422) + list(status_code = 404) } formals(mockedPOST) <- formals(httr::POST) with_mocked_bindings( @@ -63,8 +63,8 @@ test_that("Save/Load Data: bad cases", { ) |> expect_error( paste0("QSaveData has encountered an unknown error. ", - "422: The file could not properly be saved. ", - "The likely cause was an incorrect path preceding the filename." + "404: The file could not properly be saved. ", + "The likely cause was an incorrect path preceding the filename, or insufficient access to the file path." ), fixed = TRUE ) @@ -163,7 +163,7 @@ test_that("Delete Data", expect_invisible(QSaveData(mtcars, "mtcars.rds")) expect_true(QFileExists("mtcars.rds")) expect_invisible(QDeleteFiles(c("mtcars.rds"))) - expect_warning(QFileExists("mtcars.rds"), "File not found") + expect_warning(QFileExists("mtcars.rds"), "may not exist in the Displayr Cloud Drive or you may not have permission") expect_invisible(QSaveData(mtcars, "mtcars.csv")) expect_invisible(QSaveData(mtcars, "mtcars.sav")) @@ -171,8 +171,8 @@ test_that("Delete Data", expect_true(QFileExists("mtcars.sav")) expect_invisible(QDeleteFiles(c("mtcars.csv", "mtcars.sav"))) - expect_warning(QFileExists("mtcars.csv"), "File not found") - expect_warning(QFileExists("mtcars.sav"), "File not found") + expect_warning(QFileExists("mtcars.csv"), "may not exist in the Displayr Cloud Drive or you may not have permission") + expect_warning(QFileExists("mtcars.sav"), "may not exist in the Displayr Cloud Drive or you may not have permission") # Should still succeed even if files don't exist expect_invisible(QDeleteFiles(c("mtcars.csv", "mtcars.sav")))