Skip to content

Commit

Permalink
wrapper function error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellmanware committed Aug 27, 2024
1 parent 96188b0 commit 83b4787
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
10 changes: 6 additions & 4 deletions R/calculate_covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ calc_covariates <-
...
)
}, error = function(e) {
message(e)
message(args(what_to_run))
stop(
paste0(
"Please refer to the argument list and the error message above ",
"to rectify the error.\n"
e,
"\n",
paste0(deparse(args(what_to_run)), collapse = "\n"),
"\n",
"Please refer to the argument list and ",
"the error message above to rectify the error.\n"
)
)
})
Expand Down
14 changes: 10 additions & 4 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,16 @@ download_data <-
)
},
error = function(e) {
message(e)
message(args(what_to_run))
stop(paste0("Please refer to the argument list and ",
"the error message above to rectify the error.\n"))
stop(
paste0(
e,
"\n",
paste0(deparse(args(what_to_run)), collapse = "\n"),
"\n",
"Please refer to the argument list and ",
"the error message above to rectify the error.\n"
)
)
}
)
}
Expand Down
10 changes: 6 additions & 4 deletions R/process.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ process_covariates <-
...
)
}, error = function(e) {
message(e)
message(args(what_to_run))
stop(
paste0(
"Please refer to the argument list and the error message above to ",
"rectify the error.\n"
e,
"\n",
paste0(deparse(args(what_to_run)), collapse = "\n"),
"\n",
"Please refer to the argument list and ",
"the error message above to rectify the error.\n"
)
)
})
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-download.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ testthat::test_that("download_data (expected errors - directory)", {

testthat::test_that("download_data (expected errors - temporal range)", {
withr::with_tempdir({
expect_error(
testthat::expect_error(
download_geos(
date = c("1900-01-01", "2018-01-01"),
collection = "aqc_tavg_1hr_g1440x721_v1",
acknowledgement = TRUE,
directory_to_save = "."
)
)
expect_error(
testthat::expect_error(
download_aqs(
year = c(1900, 2022),
acknowledgement = TRUE,
directory_to_save = "."
)
)
expect_error(
testthat::expect_error(
download_narr(
year = c(1900, 2022),
variables = "air.sfc",
acknowledgement = TRUE,
directory_to_save = "."
)
)
expect_error(
testthat::expect_error(
download_merra2(
date = c("1900-01-01", "2023-09-01"),
collection = "inst1_2d_asm_Nx",
Expand All @@ -70,22 +70,22 @@ testthat::test_that("download_data (expected errors - temporal range)", {
)
)
sink()
expect_error(
testthat::expect_error(
download_hms(
date = c("1900-01-01", "2018-01-01"),
directory_to_save = ".",
acknowledgement = TRUE
)
)
expect_error(
testthat::expect_error(
download_gridmet(
year = c(1900, 2022),
variables = "Precipitation",
acknowledgement = TRUE,
directory_to_save = "."
)
)
expect_error(
testthat::expect_error(
download_terraclimate(
year = c(1900, 2022),
variables = "Wind Speed",
Expand Down

0 comments on commit 83b4787

Please sign in to comment.