ccb-hms / nhanes-database

4 stars 4 forks source link

download script should check for DB insertion errors #189

Open deepayan opened 5 months ago

deepayan commented 5 months ago

In download.R, the importRawTableToDb function is careful to catch errors during data download, but it assumes that once data is downloaded, the DB insertion step will always work.

This doesn't seem to hold for me, and I had a difficult time tracking this down because the resulting errors were very cryptic, like

#27 125.3 Error in `dplyr::bind_rows()`:
#27 125.3 ! Argument 10 must be a data frame or a named atomic vector.
#27 125.3 Backtrace:
#27 125.3     ▆
#27 125.3  1. └─dplyr::bind_rows(...)
#27 125.3  2.   └─rlang::abort(glue("Argument {i} must be a data frame or a named atomic vector."))
#27 125.3 Execution halted

I eventually added a call to str(parResultList) after mclapply() runs, which gives me

[...]

#27 124.9  $ :List of 4
#27 124.9   ..$    : tibble [0 × 3] (S3: tbl_df/tbl/data.frame)
#27 124.9   .. ..$ DataType: chr(0) 
#27 124.9   .. ..$ FileUrl : chr(0) 
#27 124.9   .. ..$ Error   : chr(0) 
#27 124.9   ..$    : tibble [337 × 2] (S3: tbl_df/tbl/data.frame)
#27 124.9   .. ..$ Variable : chr [1:337] "SEQN" "AUXRR101" "AUXRR102" "AUXRR103" ...
#27 124.9   .. ..$ TableName: Named chr [1:337] "AUXAR_G" "AUXAR_G" "AUXAR_G" "AUXAR_G" ...
#27 124.9   .. .. ..- attr(*, "names")= chr [1:337] "AUXAR_G" "AUXAR_G" "AUXAR_G" "AUXAR_G" ...
#27 124.9   ..$ i  : int 9
#27 124.9   ..$ url: chr "/Nchs/Nhanes/2011-2012/AUXAR_G.XPT"
#27 124.9  $ : 'try-error' chr "Error : Internal error: load failed. The detailed error information is listed in err.log. [1815]\n"
#27 124.9   ..- attr(*, "condition")=List of 2
#27 124.9   .. ..$ message: chr "Internal error: load failed. The detailed error information is listed in err.log. [1815]"
#27 124.9   .. ..$ call   : NULL
#27 124.9   .. ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
#27 124.9  $ : 'try-error' chr "Error : Internal error: load failed. The detailed error information is listed in err.log. [1815]\n"
#27 124.9   ..- attr(*, "condition")=List of 2
#27 124.9   .. ..$ message: chr "Internal error: load failed. The detailed error information is listed in err.log. [1815]"
#27 124.9   .. ..$ call   : NULL
#27 124.9   .. ..- attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
#27 124.9  $ :List of 4
#27 124.9   ..$    : tibble [0 × 3] (S3: tbl_df/tbl/data.frame)
#27 124.9   .. ..$ DataType: chr(0) 
#27 124.9   .. ..$ FileUrl : chr(0) 
#27 124.9   .. ..$ Error   : chr(0) 
#27 124.9   ..$    : tibble [171 × 2] (S3: tbl_df/tbl/data.frame)
#27 124.9   .. ..$ Variable : chr [1:171] "SEQN" "WTSAU2YR" "WTSAU4YR" "AUDTYR01" ...
#27 124.9   .. ..$ TableName: Named chr [1:171] "AUXTYM" "AUXTYM" "AUXTYM" "AUXTYM" ...
#27 124.9   .. .. ..- attr(*, "names")= chr [1:171] "AUXTYM" "AUXTYM" "AUXTYM" "AUXTYM" ...
#27 124.9   ..$ i  : int 12
#27 124.9   ..$ url: chr "/Nchs/Nhanes/1999-2000/AUXTYM.XPT"

[...]

I am still trying to figure out why this is happening, but it would be nice to have this caught and reported more gracefully.