Does this look like reasonable code to capture an error, flag that there was an error, log it, and move on?
8 cdb.retrieveData <- function(url) {
9 errors <- c()
10 success <- TRUE
11 onError <- function(e) {
12 errors <<- c(errors, sprintf("Failed retrieval \"%s\", error: %s",
13 url, e$message))
14 success <<- FALSE
15 list()
16 }
17 data <- tryCatch(fromJSON(url), error=onError, warning=onError)
18 list(url=url, success=success, errors=errors, data=data)
19 }
I think the list()
of line 15 will be returned from tryCatch()
on error and take the place of data
in the returned list.
The code looks pretty similar to that suggested in https://stackoverflow.com/a/39898082/608359 Is there a better way?
This code is producing "Error in sprintf("Failed retrieval \"%s\", error: %s", url, e$message) :
promise already under evaluation: recursive default argument reference or earlier problems?
". What is the cause?
If it matters, the caller is a reduce
from purrr
whose reducer combines the returned lists into one. The mess that calls it is this source processContests.R
I'm afraid I haven't been able to reproduce the error in a test. It's probably premature of me to be asking here. Here's the series of calls which gets me to the error.
> cdb <- CDBContests('https://iaccdb.iac.org')
> ctsts <- cdb$allContests()
> pc <- ProcessContests(ctsts)
> pc$process()
[1] Processed records file, "pc_processed.rds" retrieval error: "cannot open compressed file 'pc_processed.rds', probable reason 'No such file or directory'". NOTE: Processing all contests.
[1] Errors file, "pc_errors.rds" retrieval error: "cannot open compressed file 'pc_errors.rds', probable reason 'No such file or directory'". Will start one.
[1] Data file, "pc_data.rds" retrieval error: "cannot open compressed file 'pc_data.rds', probable reason 'No such file or directory'". Starting data file.
Error in sprintf("Failed retrieval \"%s\", error: %s", url, e$message) :
promise already under evaluation: recursive default argument reference or earlier problems?
>