Skip to content

Commit

Permalink
refactor: Tweak 'img_read()' error messages
Browse files Browse the repository at this point in the history
* Don't include calling function name in error mesage
* More consistency between `img_read()` error messages
* Otherwise no big changes, message already communicates
  there was a problem with downloading image, not sure
  how that should change.

closes #69
  • Loading branch information
trevorld committed Apr 22, 2024
1 parent b12a249 commit 4be21fa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/utils-magick-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ img_read <- function(filename) {
if (identical(filename, '')) {
return(magick::image_blank(100, 100, color = 'none'))
}
if (is.null(filename) || length(filename)==0 || is.na(filename) || filename == '') {
abort(paste0("img_read(): bad filename: ", deparse(filename)))
if (is.null(filename) || length(filename)== 0 || is.na(filename) || filename == '') {
abort(paste0("bad filename: ", deparse(filename)))
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -18,7 +18,7 @@ img_read <- function(filename) {
img <- tryCatch(
{magick::image_read(filename)},
error = function(cond) {
msg <- c(glue("img_read() non-specific error with magick::image_read({shQuote(filename)})"),
msg <- c(glue("couldn't read {shQuote(filename)}"),
i = cond$message)
abort(msg)
}
Expand Down Expand Up @@ -49,7 +49,7 @@ img_read_as_array <- function(filename, width = NULL, height = NULL,
img <- img_read_memoised(filename)

if (is.null(img)) {
abort(glue("img_read_as_array(): couldn't read '{filename}'"))
abort(glue("couldn't read {shQuote(filename)}"))
}

img <- fill_area_with_img(img, width, height, type = fill_type, gravity = gravity,
Expand Down

0 comments on commit 4be21fa

Please sign in to comment.