diff --git a/R/io.R b/R/io.R index fdb4260fb..a0d8c2168 100644 --- a/R/io.R +++ b/R/io.R @@ -54,7 +54,11 @@ transform_utf8_one <- function(path, fun, dry) { if (inherits(e, "dryError")) { rlang::abort(conditionMessage(e)) } - warn(paste0("When processing ", path, ": ", conditionMessage(e))) + show_path <- cli::style_hyperlink( + cli::col_blue(basename(path)), + paste0("file://", path) + ) + cli::cli_warn("When processing {show_path}:", parent = e) NA } ) diff --git a/R/parse.R b/R/parse.R index 3af0146bc..d4bacd1c4 100644 --- a/R/parse.R +++ b/R/parse.R @@ -15,25 +15,26 @@ #' #' styler:::parse_safely("a + 3 -4 -> \n glück + 1") parse_safely <- function(text, ...) { - tried_parsing <- rlang::try_fetch( + tried_parsing <- withCallingHandlers( parse(text = text, ...), - error = function(e) e, - warning = function(w) w - ) - if (inherits(tried_parsing, "error")) { - if (has_crlf_as_first_line_sep(tried_parsing$message, text)) { - abort(paste0( - "The code to style seems to use Windows style line endings (CRLF). ", - "styler currently only supports Unix style line endings (LF). ", - "Please change the EOL character in your editor to Unix style and try ", - "again.\nThe parsing error was:\n", tried_parsing$message - )) - } else { - abort(tried_parsing$message) + error = function(e) { + if (has_crlf_as_first_line_sep(e$message, text)) { + msg <- c( + x = "The code to style seems to use Windows style line endings (CRLF).", + `!` = "styler currently only supports Unix style line endings (LF). ", + i = "Please change the EOL character in your editor to Unix style + and try again." + ) + } else { + msg <- c(x = "Styling failed") + } + cli::cli_abort(msg, parent = e, call = NULL) + }, + warning = function(w) { + cli::cli_warn(w$message) + w } - } else if (inherits(tried_parsing, "warning")) { - warn(tried_parsing$message) - } + ) tried_parsing } diff --git a/R/testing.R b/R/testing.R index 5495d3580..bce9f8b3c 100644 --- a/R/testing.R +++ b/R/testing.R @@ -117,7 +117,7 @@ transform_and_check <- function(in_item, out_item, unclass() if (!file.exists(out_item)) { warn(paste( - "File", out_item, "does not exist. Creating it from transormation." + "File", out_item, "does not exist. Creating it from transformation." )) file.create(out_item) }