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
6 changes: 5 additions & 1 deletion R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
Expand Down
35 changes: 18 additions & 17 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion R/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down