Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"))
Expand All @@ -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
30 changes: 7 additions & 23 deletions R/aaa-conditions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
18 changes: 0 additions & 18 deletions man/dot-compile_error_class.Rd

This file was deleted.

4 changes: 2 additions & 2 deletions man/dot-hrmn_abort.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions tests/testthat/_snaps/aaa-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/jonthegeek/hrmn/issues> with a reprex (<https://tidyverse.org/help/>) 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
Expand Down
61 changes: 3 additions & 58 deletions tests/testthat/test-aaa-conditions.R
Original file line number Diff line number Diff line change
@@ -1,70 +1,15 @@
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"),
error = TRUE
)
})

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))
Expand Down