Skip to content

Commit

Permalink
Improved error and warning handling in deliver
Browse files Browse the repository at this point in the history
  • Loading branch information
JBGruber committed Nov 8, 2023
1 parent d6d1ba1 commit 5142cc7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: paperboy
Title: Comprehensive Collection of News Media Scrapers
Version: 0.0.5.9000
Date: 2023-11-07
Date: 2023-11-08
Authors@R:
person(given = "Johannes B.",
family = "Gruber",
Expand Down
19 changes: 12 additions & 7 deletions R/deliver.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pb_deliver.data.frame <- function(x, try_default = TRUE, ignore_fails = FALSE, v
if (isTRUE(verbose) && isTRUE(sum(!sel) > 0)) {
cli::cli_alert_warning(c(
"{sum(!sel)} URL{?s} removed as no parser is available for the domain{?s}. ",
"Set {.fn try_default = TRUE} to try a generic parser for unknown domains."
"Set {.code try_default = TRUE} to try a generic parser for unknown domains."
))
}
}
Expand Down Expand Up @@ -126,11 +126,16 @@ pb_deliver_paper <- function(x, verbose, pb, ...) {
#' version of pb_deliver_paper that supresses errors
#' @noRd
s_pb_deliver_paper <- function(x, ...) {
tryCatch(pb_deliver_paper(x, ...), error = function(e) {
e <<- e
msg <- paste0("Problem: ", conditionMessage(e), x$expanded_url, "\n")
cli::cli_alert_danger(msg)
return(list())
})
tryCatch(pb_deliver_paper(x, ...),
error = function(e) {
msg <- paste0("Problem: ", conditionMessage(e), ". URL: ", x$expanded_url, "\n")
cli::cli_alert_danger(msg)
return(list())
},
warning = function(w) {
msg <- paste0("Warning: ", conditionMessage(w), ". URL: ", x$expanded_url, "\n")
cli::cli_alert_info(msg)
return(NULL)
})
}

3 changes: 2 additions & 1 deletion R/deliver_idnes_cz.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pb_deliver_paper.idnes_cz <- function(x, verbose = NULL, pb, ...) {

cover_image_html <- html %>%
rvest::html_elements(".art-full img,video") %>%
as.character()
as.character() %>%
paste(collapse = "\n")

cover_image_url <- html %>%
rvest::html_element(".art-full img,video") %>%
Expand Down

0 comments on commit 5142cc7

Please sign in to comment.