Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure there are no unknown named arguments fix #140 #141

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 15 additions & 0 deletions R/logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,32 +311,47 @@ validate_log_level <- function(level) {
}


#' Make sure there are no unknown named arguments
#' @keywords internal
assert_no_unknown_args <- function() {
call <- match.call(definition = sys.function(1), call = sys.call(1), expand.dots = FALSE)
stopifnot("Unknown named argument provided." = is.null(names(call$`...`)))
Copy link
Contributor

@MichaelChirico MichaelChirico Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better to supply the argument(s)?

Suggested change
stopifnot("Unknown named argument provided." = is.null(names(call$`...`)))
if (!is.null(unknown_names <- names(call$`...`))) {
stop("Unknown argument(s) provided: ", toString(unknown_names))
}

}


#' @export
log_fatal <- function(...) {
assert_no_unknown_args()
log_level(FATAL, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
}
#' @export
log_error <- function(...) {
assert_no_unknown_args()
log_level(ERROR, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
}
#' @export
log_warn <- function(...) {
assert_no_unknown_args()
log_level(WARN, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
}
#' @export
log_success <- function(...) {
assert_no_unknown_args()
log_level(SUCCESS, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
}
#' @export
log_info <- function(...) {
assert_no_unknown_args()
log_level(INFO, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
}
#' @export
log_debug <- function(...) {
assert_no_unknown_args()
log_level(DEBUG, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
}
#' @export
log_trace <- function(...) {
assert_no_unknown_args()
log_level(TRACE, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
}

Expand Down
Loading