|
15 | 15 | #' |
16 | 16 | #' styler:::parse_safely("a + 3 -4 -> \n glück + 1") |
17 | 17 | parse_safely <- function(text, ...) { |
18 | | - tried_parsing <- rlang::try_fetch( |
| 18 | + tried_parsing <- withCallingHandlers( |
19 | 19 | parse(text = text, ...), |
20 | | - error = function(e) e, |
21 | | - warning = function(w) w |
22 | | - ) |
23 | | - if (inherits(tried_parsing, "error")) { |
24 | | - if (has_crlf_as_first_line_sep(tried_parsing$message, text)) { |
25 | | - abort(paste0( |
26 | | - "The code to style seems to use Windows style line endings (CRLF). ", |
27 | | - "styler currently only supports Unix style line endings (LF). ", |
28 | | - "Please change the EOL character in your editor to Unix style and try ", |
29 | | - "again.\nThe parsing error was:\n", tried_parsing$message |
30 | | - )) |
31 | | - } else { |
32 | | - abort(tried_parsing$message) |
| 20 | + error = function(e) { |
| 21 | + if (has_crlf_as_first_line_sep(e$message, text)) { |
| 22 | + msg <- c( |
| 23 | + x = "The code to style seems to use Windows style line endings (CRLF).", |
| 24 | + `!` = "styler currently only supports Unix style line endings (LF). ", |
| 25 | + i = "Please change the EOL character in your editor to Unix style |
| 26 | + and try again." |
| 27 | + ) |
| 28 | + } else { |
| 29 | + msg <- c(x = "Styling failed") |
| 30 | + } |
| 31 | + cli::cli_abort(msg, parent = e, call = NULL) |
| 32 | + }, |
| 33 | + warning = function(w) { |
| 34 | + cli::cli_warn(w$message) |
| 35 | + w |
33 | 36 | } |
34 | | - } else if (inherits(tried_parsing, "warning")) { |
35 | | - warn(tried_parsing$message) |
36 | | - } |
| 37 | + ) |
37 | 38 | tried_parsing |
38 | 39 | } |
39 | 40 |
|
|
0 commit comments