Skip to content
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
19 changes: 7 additions & 12 deletions R/DataMart.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be changed on the Displayr side as well.

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)
{
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test-datamart.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
Expand Down Expand Up @@ -163,16 +163,16 @@ 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"))
expect_true(QFileExists("mtcars.csv"))
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")))
Expand Down
Loading