Skip to content

Commit

Permalink
Display error prefixes in red experimentally
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jan 9, 2024
1 parent 81c7dcd commit 29599cc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion R/cnd-message.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,13 @@ cnd_message_format_prefixed <- function(cnd,

if (parent) {
prefix <- sprintf("Caused by %s", type)
# FIXME: Enable this by default later on
if (use_red_error_prefix()) {
prefix <- col_prefix(prefix, type)
}
} else {
prefix <- col_yellow(capitalise(type))
prefix <- capitalise(type)
prefix <- col_prefix(prefix, type)
}

evalq({
Expand Down Expand Up @@ -270,6 +275,18 @@ cnd_message_format_prefixed <- function(cnd,
}
}

col_prefix <- function(prefix, type) {
if (type == "error" && use_red_error_prefix()) {
col_red(prefix)
} else {
col_yellow(prefix)
}
}

use_red_error_prefix <- function() {
peek_option("rlang:::use_red_error_prefix") %||% FALSE
}

peek_call_format_srcref <- function() {
opt <- peek_option("rlang_call_format_srcrefs")
if (is_null(opt)) {
Expand Down

0 comments on commit 29599cc

Please sign in to comment.