Browse Source

wrap long error messages elsewhere in pkg

tags/v0.3.0
Garrick Aden-Buie 6 years ago
parent
commit
e482243b09
2 changed files with 8 additions and 8 deletions
  1. +7
    -7
      R/style_extra_css.R
  2. +1
    -1
      tests/testthat/test-style_extra_css.R

+ 7
- 7
R/style_extra_css.R View File

stop("All elements in `css` list must be named", call. = FALSE) stop("All elements in `css` list must be named", call. = FALSE)
} }
if (purrr::vec_depth(css) != 3) { if (purrr::vec_depth(css) != 3) {
stop(
stop(str_wrap(
"`css` list must be a named list within a named list, e.g.:\n", "`css` list must be a named list within a named list, e.g.:\n",
' list(".class-id" = list("css-property" = "value"))' ' list(".class-id" = list("css-property" = "value"))'
)
))
} }
if (any(names(css) == "")) { if (any(names(css) == "")) {
not_named <- which(names(css) == "") not_named <- which(names(css) == "")
if (length(not_named) > 1) { if (length(not_named) > 1) {
stop(
stop(str_wrap(
call. = FALSE, call. = FALSE,
"All elements in `css` list must be named. Items ", "All elements in `css` list must be named. Items ",
paste(not_named, collapse = ", "), paste(not_named, collapse = ", "),
" are unnamed." " are unnamed."
)
))
} else { } else {
stop(
stop(str_wrap(
call. = FALSE, call. = FALSE,
"All elements in `css` list must be named. Item ", "All elements in `css` list must be named. Item ",
not_named, not_named,
" is not named." " is not named."
)
))
} }
} }
child_unnamed <- purrr::map_lgl(purrr::map(css, ~ { child_unnamed <- purrr::map_lgl(purrr::map(css, ~ {
if (length(has_unnamed) > 1) "have" else "has", if (length(has_unnamed) > 1) "have" else "has",
"unnamed property or properties." "unnamed property or properties."
) )
stop(msg, call. = FALSE)
stop(str_wrap(msg), call. = FALSE)
} }


x <- purrr::imap_chr(css, function(rules, selector) { x <- purrr::imap_chr(css, function(rules, selector) {

+ 1
- 1
tests/testthat/test-style_extra_css.R View File

) )
expect_error( expect_error(
list2css(list(body = list("#bad"), thing = list("#bad"))), list2css(list(body = list("#bad"), thing = list("#bad"))),
"elements.+must be named.+body, thing.+have"
"elements.+must be named.+body.+thing.+have"
) )
}) })



Loading…
Cancel
Save