diff --git a/DESCRIPTION b/DESCRIPTION index 1532583..024874d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hrmn Title: Harmonize Datasets -Version: 0.0.0.9003 +Version: 0.0.0.9004 Authors@R: person("Jon", "Harmon", , "jonthegeek@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4781-4346")) @@ -14,15 +14,16 @@ URL: https://jonthegeek.github.io/hrmn/, BugReports: https://github.com/jonthegeek/hrmn/issues Depends: R (>= 4.1) +Imports: + fastmatch, + rlang, + stbl (>= 0.2.0.9002) Suggests: testthat (>= 3.0.0) +Remotes: + stbl=api2r/stbl Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.3 -Imports: - cli, - fastmatch, - rlang, - stbl diff --git a/R/aaa-conditions.R b/R/aaa-conditions.R index 994888f..8e21c79 100644 --- a/R/aaa-conditions.R +++ b/R/aaa-conditions.R @@ -8,13 +8,9 @@ rlang::caller_env #' Signal an error with standards applied #' -#' A wrapper around [cli::cli_abort()] to throw classed errors. +#' A wrapper around [stbl::pkg_abort()] to throw classed errors. #' -#' @param message (`character`) The message for the new error. Messages will be -#' formatted with [cli::cli_bullets()]. -#' @param ... Additional parameters passed to [cli::cli_abort()] and on to -#' [rlang::abort()]. -#' @inheritParams .shared_params +#' @inheritParams stbl::pkg_abort #' @keywords internal .hrmn_abort <- function( message, @@ -24,29 +20,17 @@ rlang::caller_env parent = NULL, ... ) { - cli::cli_abort( - message, - class = c( - .compile_error_class("hrmn", "error", subclass), - .compile_error_class("hrmn", "error"), - .compile_error_class("hrmn", "condition") - ), + stbl::pkg_abort( + "hrmn", + message = message, + subclass = subclass, call = call, - .envir = message_env, + message_env = message_env, parent = parent, ... ) } -#' Compile an error class -#' -#' @param ... `(character)` Components of the class name. -#' @returns A length-1 character vector. -#' @keywords internal -.compile_error_class <- function(...) { - paste(..., sep = "-") -} - #' Check that all specified args are named #' #' @param ... Arguments to check. diff --git a/man/dot-compile_error_class.Rd b/man/dot-compile_error_class.Rd deleted file mode 100644 index 285ff3c..0000000 --- a/man/dot-compile_error_class.Rd +++ /dev/null @@ -1,18 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/aaa-conditions.R -\name{.compile_error_class} -\alias{.compile_error_class} -\title{Compile an error class} -\usage{ -.compile_error_class(...) -} -\arguments{ -\item{...}{\code{(character)} Components of the class name.} -} -\value{ -A length-1 character vector. -} -\description{ -Compile an error class -} -\keyword{internal} diff --git a/man/dot-hrmn_abort.Rd b/man/dot-hrmn_abort.Rd index d045c51..34c2b96 100644 --- a/man/dot-hrmn_abort.Rd +++ b/man/dot-hrmn_abort.Rd @@ -18,7 +18,7 @@ formatted with \code{\link[cli:cli_bullets]{cli::cli_bullets()}}.} \item{subclass}{(\code{character}) Class(es) to assign to the error. Will be -prefixed by "hrmn-error-".} +prefixed by "\{package\}-error-".} \item{call}{\code{(environment)} The execution environment to mention as the source of error messages.} @@ -33,6 +33,6 @@ evaluate variables in error messages.} \code{\link[rlang:abort]{rlang::abort()}}.} } \description{ -A wrapper around \code{\link[cli:cli_abort]{cli::cli_abort()}} to throw classed errors. +A wrapper around \code{\link[stbl:pkg_abort]{stbl::pkg_abort()}} to throw classed errors. } \keyword{internal} diff --git a/tests/testthat/_snaps/aaa-conditions.md b/tests/testthat/_snaps/aaa-conditions.md index c1e1b13..c3918d9 100644 --- a/tests/testthat/_snaps/aaa-conditions.md +++ b/tests/testthat/_snaps/aaa-conditions.md @@ -6,34 +6,6 @@ Error: ! A message. -# .hrmn_abort() uses parent when provided - - Code - .hrmn_abort("child message", "child_class", parent = parent_cnd) - Condition - Error: - ! child message - Caused by error: - ! parent message - -# .hrmn_abort() passes dots to cli_abort() - - Code - .hrmn_abort("A message.", "a_subclass", .internal = TRUE) - Condition - Error: - ! A message. - i This is an internal error that was detected in the hrmn package. - Please report it at with a reprex () and the full backtrace. - -# .hrmn_abort() uses message_env when provided - - Code - .hrmn_abort("This message comes from {var}.", "subclass", message_env = msg_env) - Condition - Error: - ! This message comes from a custom environment. - # .check_args_named() works Code diff --git a/tests/testthat/test-aaa-conditions.R b/tests/testthat/test-aaa-conditions.R index d221e07..3b6fb80 100644 --- a/tests/testthat/test-aaa-conditions.R +++ b/tests/testthat/test-aaa-conditions.R @@ -1,15 +1,8 @@ test_that(".hrmn_abort() throws the expected error", { - expect_error( - .hrmn_abort("A message.", "a_subclass"), - class = "hrmn-error-a_subclass" - ) - expect_error( + stbl::expect_pkg_error_classes( .hrmn_abort("A message.", "a_subclass"), - class = "hrmn-error" - ) - expect_error( - .hrmn_abort("A message.", "a_subclass"), - class = "hrmn-condition" + "hrmn", + "a_subclass" ) expect_snapshot( .hrmn_abort("A message.", "a_subclass"), @@ -17,54 +10,6 @@ test_that(".hrmn_abort() throws the expected error", { ) }) -test_that(".hrmn_abort() uses parent when provided", { - parent_cnd <- rlang::catch_cnd(cli::cli_abort("parent message")) - expect_snapshot( - .hrmn_abort("child message", "child_class", parent = parent_cnd), - error = TRUE - ) -}) - -test_that(".hrmn_abort() passes dots to cli_abort()", { - expect_error( - .hrmn_abort("A message.", "a_subclass", .internal = TRUE), - class = "hrmn-error-a_subclass" - ) - expect_snapshot( - .hrmn_abort("A message.", "a_subclass", .internal = TRUE), - error = TRUE - ) -}) - -test_that(".hrmn_abort() uses message_env when provided", { - var <- "a locally defined var" - msg_env <- new.env() - msg_env$var <- "a custom environment" - expect_snapshot( - .hrmn_abort( - "This message comes from {var}.", - "subclass", - message_env = msg_env - ), - error = TRUE - ) -}) - -test_that(".compile_error_class() works", { - expect_equal( - .compile_error_class("hrmn", "error", "my_subclass"), - "hrmn-error-my_subclass" - ) - expect_equal( - .compile_error_class("hrmn", "error"), - "hrmn-error" - ) - expect_equal( - .compile_error_class("hrmn", "condition"), - "hrmn-condition" - ) -}) - test_that(".check_args_named() works", { expect_no_error(.check_args_named()) expect_no_error(.check_args_named(a = 1))