Skip to content

Commit d01b6e3

Browse files
committed
turn preschedule on, add test
1 parent 34d75d2 commit d01b6e3

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

facebook/delphiFacebook/R/responses.R

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@
1919
load_responses_all <- function(params, contingency_run = FALSE) {
2020
msg_plain(paste0("Loading ", length(params$input), " CSVs"))
2121

22-
# To prevent errors from one file from "contaminating" output for other files
23-
# that happen to be in the same `mclapply` group, turn `mc.preschedule` off.
24-
# This makes debugging problematic input files easier.
25-
# See https://stackoverflow.com/questions/18330274/an-error-in-one-job-contaminates-others-with-mclapply
26-
# for details.
27-
mclapply_no_preschedule <- function(...) {
28-
mclapply(..., mc.preschedule = FALSE)
29-
}
30-
31-
map_fn <- if (params$parallel) { mclapply_no_preschedule } else { lapply }
22+
map_fn <- if (params$parallel) { mclapply } else { lapply }
3223
input_data <- map_fn(seq_along(params$input), function(i) {
3324
load_response_one(params$input[i], params, contingency_run)
3425
})
@@ -38,7 +29,12 @@ load_responses_all <- function(params, contingency_run = FALSE) {
3829
which_errors <- unlist(lapply(input_data, inherits, "try-error"))
3930
if (any( which_errors )) {
4031
errored_filenames <- paste(params$input[which_errors], collapse=", ")
41-
stop("ingestion and field creation failed for input data file(s)", errored_filenames)
32+
stop(
33+
"ingestion and field creation failed for at least one of input data file(s) ",
34+
errored_filenames,
35+
" with error(s)\n",
36+
unique(input_data[which_errors])
37+
)
4238
}
4339

4440
input_data <- bind_rows(input_data)

facebook/delphiFacebook/integration-tests/testthat/test-integration.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,10 @@ test_that("testing national aggregation", {
385385
}
386386

387387
})
388+
389+
test_that("testing load_responses behavior for missing input", {
390+
params <- relativize_params(read_params(test_path("params-test.json")))
391+
params$input <- c(params$input, "file-does-not-exist.csv")
392+
params$parallel <- TRUE
393+
expect_error(load_responses_all(params), regexp="ingestion and field creation failed")
394+
})

0 commit comments

Comments
 (0)