From 9937ed91ec71b721255fcf6ec6beccb6596caa2b Mon Sep 17 00:00:00 2001 From: David Young Date: Tue, 6 Jan 2026 17:19:29 +1100 Subject: [PATCH 1/5] SS-1263: Initial changes to error messages in datamart R code --- R/DataMart.R | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/R/DataMart.R b/R/DataMart.R index 6cb7bf0..4e12cfe 100644 --- a/R/DataMart.R +++ b/R/DataMart.R @@ -13,7 +13,7 @@ MAX.FILENAME.LENGTH <- 100L #' #' @return TRUE if the file exists, otherwise FALSE. #' -#' @importFrom httr HEAD add_headers +#' @importFrom httr HEAD add_headers content #' @importFrom utils URLencode #' #' @export @@ -30,8 +30,13 @@ 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.") + if (show.warning) { + err <- tryCatch(content(res, as = "text", encoding = "UTF-8"), + error = function(e) "") + if (!nzchar(err)) + err <- "File not found." + warning(err) + } return (FALSE) } else @@ -92,7 +97,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 +229,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) } @@ -348,11 +350,13 @@ QSaveData <- function(object, filename, compression.file.size.threshold = NULL, { 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.") + err <- tryCatch(content(res, as = "text", encoding = "UTF-8"), + error = function(e) "") + if (!nzchar(err)) + err <- "Could not save file." + stop("QSaveData has encountered an unknown error. ", err, call. = FALSE) } else if (has.errored || res$status_code != 200) { @@ -407,6 +411,10 @@ 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) + err <- tryCatch(content(res, as = "text", encoding = "UTF-8"), + error = function(e) "") + if (nzchar(err)) + stop("Could not delete files: ", filenames.string, ". ", err, call. = FALSE) stopBadRequest(res, paste0("Could not delete files: ", filenames.string)) } msg <- paste0("Successfully deleted files: ", filenames.string) From 472128cc39c9b784258839e1dfa1df85e13acebf Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 14 Jan 2026 15:45:00 +1100 Subject: [PATCH 2/5] Simplify error messages. Handle within flipAPI --- R/DataMart.R | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/R/DataMart.R b/R/DataMart.R index 4e12cfe..63b9380 100644 --- a/R/DataMart.R +++ b/R/DataMart.R @@ -13,7 +13,7 @@ MAX.FILENAME.LENGTH <- 100L #' #' @return TRUE if the file exists, otherwise FALSE. #' -#' @importFrom httr HEAD add_headers content +#' @importFrom httr HEAD add_headers #' @importFrom utils URLencode #' #' @export @@ -30,13 +30,8 @@ QFileExists <- function(filename, show.warning = TRUE, company.token = NA, docum if (is.null(res$status_code) || res$status_code != 200) { - if (show.warning) { - err <- tryCatch(content(res, as = "text", encoding = "UTF-8"), - error = function(e) "") - if (!nzchar(err)) - err <- "File not found." - warning(err) - } + if (show.warning) + warning("This file may not exist in the Displayr Cloud Drive or you may not have permission to access it.") return (FALSE) } else @@ -347,21 +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 == 404) - { - err <- tryCatch(content(res, as = "text", encoding = "UTF-8"), - error = function(e) "") - if (!nzchar(err)) - err <- "Could not save file." - stop("QSaveData has encountered an unknown error. ", err, call. = FALSE) - } else if (has.errored || res$status_code != 200) { - warning("QSaveData has encountered an unknown error.") - stopBadRequest(res, "Could not save file.") + 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, or insufficient access to the file path.") } if (!is.compressed) { @@ -411,11 +397,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) - err <- tryCatch(content(res, as = "text", encoding = "UTF-8"), - error = function(e) "") - if (nzchar(err)) - stop("Could not delete files: ", filenames.string, ". ", err, call. = FALSE) - 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) From 0bcdfdb227dd82945e11acdcf85f9a989ba0ed64 Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 14 Jan 2026 15:47:10 +1100 Subject: [PATCH 3/5] Retains previous fail on other non 200 errors. --- R/DataMart.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/DataMart.R b/R/DataMart.R index 63b9380..85776eb 100644 --- a/R/DataMart.R +++ b/R/DataMart.R @@ -343,12 +343,17 @@ QSaveData <- function(object, filename, compression.file.size.threshold = NULL, 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 != 200) + else if (!has.errored && res$status_code == 404) { stop("QSaveData has encountered an unknown error. ", - "422: The file could not properly be saved. ", + "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) + { + warning("QSaveData has encountered an unknown error.") + stopBadRequest(res, "Could not save file.") + } if (!is.compressed) { if (type != "gif") From 4dc902df26a51769988a06e59876e0ca01e818c2 Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 14 Jan 2026 16:28:14 +1100 Subject: [PATCH 4/5] Fix tests --- tests/testthat/test-datamart.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-datamart.R b/tests/testthat/test-datamart.R index 9e72e4d..f73f2f8 100644 --- a/tests/testthat/test-datamart.R +++ b/tests/testthat/test-datamart.R @@ -46,8 +46,8 @@ 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 @@ -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"))) From f7dddca590ab530e2809e27294c3be914649b805 Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 14 Jan 2026 16:34:52 +1100 Subject: [PATCH 5/5] Fix test again --- tests/testthat/test-datamart.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-datamart.R b/tests/testthat/test-datamart.R index f73f2f8..b8bdaf6 100644 --- a/tests/testthat/test-datamart.R +++ b/tests/testthat/test-datamart.R @@ -52,9 +52,9 @@ test_that("Save/Load Data: bad cases", { # 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 )