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
38 changes: 22 additions & 16 deletions R/standalone-errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,9 @@ err <- local({

format_header_line_cli <- function(x, prefix = NULL) {
p_error <- format_error_heading_cli(x, prefix)
p_call <- format_call_cli(x[["call"]])
p_srcref <- format_srcref_cli(conditionCall(x), x$procsrcref %||% x$srcref)
paste0(p_error, p_call, p_srcref, if (!is.null(conditionCall(x))) ":")
p_call <- format_call_cli(conditionCall(x))
p_srcref <- format_srcref_cli(p_call, x$procsrcref %||% x$srcref)
paste0(p_error, p_call, p_srcref, if (!is.null(p_call)) ":")
}

format_class_cli <- function(x) {
Expand Down Expand Up @@ -1006,9 +1006,9 @@ err <- local({
ifelse(visible, "", "| "),
scope,
vapply(
seq_along(x$call),
seq_along(x[["call"]]),
function(i) {
format_trace_call_cli(x$call[[i]], x$namespace[[i]])
format_trace_call_cli(x[["call"]][[i]], x$namespace[[i]])
},
character(1)
),
Expand Down Expand Up @@ -1115,7 +1115,7 @@ err <- local({

format_header_line_plain <- function(x, prefix = NULL) {
p_error <- format_error_heading_plain(x, prefix)
p_call <- format_call_plain(x[["call"]])
p_call <- format_call_plain(conditionCall(x))
p_srcref <- format_srcref_plain(
conditionCall(x),
x$procsrcref %||% x$srcref
Expand Down Expand Up @@ -1189,15 +1189,17 @@ err <- local({
nchar(x, type = "bytes")
}

minimize_call <- function(call) {
if (!is.call(call)) return(call)
dep <- deparse(call, nlines = 2)
result <- tryCatch(str2lang(dep[[1L]]), error = function(e) NULL)
if (!is.null(result)) return(result)
tryCatch(as.call(list(call[[1L]], quote(...))), error = function(e) NULL)
}

process_call <- function(cond) {
cond[c("call", "srcref", "procsrcref")] <- list(
call = if (is.null(cond[["call"]])) {
NULL
} else if (is.character(cond[["call"]])) {
cond[["call"]]
} else {
deparse(cond[["call"]], nlines = 2)
},
call = minimize_call(cond[["call"]]),
srcref = NULL,
procsrcref = get_srcref(cond[["call"]], cond$procsrcref %||% cond$srcref)
)
Expand Down Expand Up @@ -1301,9 +1303,13 @@ err <- local({
}

frame_call <- function(frame) {
out <- NULL
delayedAssign("out", base::sys.call(), frame)
out
frames <- sys.frames()
for (i in seq_along(frames)) {
if (identical(frames[[i]], frame)) {
return(sys.call(i))
}
}
NULL
}

# Useful for snapshots so that they print without an unstable backtrace.
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/Darwin/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
Code
process$new(tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! cannot start processx process '<tempdir>/<tempfile>' (system error 2, No such file or directory) @unix/processx.c:651 (processx_exec)

# working directory does not exist

Code
process$new(px, wd = tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! cannot start processx process '<path>/px' (system error 2, No such file or directory) @unix/processx.c:651 (processx_exec)

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/Darwin/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Code
run(px, wd = tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! cannot start processx process '<path>/px' (system error 2, No such file or directory) @unix/processx.c:651 (processx_exec)

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/Darwin/unix-sockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
conn_read_chars(sock1)
Condition
Error:
Error in `processx_conn_read_chars()`:
! ! Native call to `processx_connection_read_chars` failed
Caused by error in `chain_call(c_processx_connection_read_chars, con, n)` at connections.R:302:<col>:
! Cannot read from processx connection (system error 57, Socket is not connected) @processx-connection.c:1891 (processx__connection_read)
Expand All @@ -13,21 +13,21 @@
Code
conn_create_unix_socket(sock)
Condition
Error:
Error in `conn_create_unix_socket()`:
! ! Native call to `processx_connection_create_socket` failed
Caused by error in `chain_call(c_processx_connection_create_socket, filename, encoding)` at connections.R:618:<col>:
! Server socket path too long: <tempdir>/<tempfile>
Code
conn_create_unix_socket("/dev/null")
Condition
Error:
Error in `conn_create_unix_socket()`:
! ! Native call to `processx_connection_create_socket` failed
Caused by error in `chain_call(c_processx_connection_create_socket, filename, encoding)` at connections.R:618:<col>:
! Cannot bind to socket (system error 48, Address already in use) @processx-connection.c:479 (processx_connection_create_socket)
Code
conn_connect_unix_socket("/dev/null")
Condition
Error:
Error in `conn_connect_unix_socket()`:
! ! Native call to `processx_connection_connect_socket` failed
Caused by error in `chain_call(c_processx_connection_connect_socket, filename, encoding)` at connections.R:640:<col>:
! Cannot connect to socket (system error 38, Socket operation on non-socket) @processx-connection.c:550 (processx_connection_connect_socket)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/Linux/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
Code
process$new(tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! cannot start processx process '<tempdir>/<tempfile>' (system error 2, No such file or directory) @unix/processx.c:651 (processx_exec)

# working directory does not exist

Code
process$new(px, wd = tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! cannot start processx process '<path>/px' (system error 2, No such file or directory) @unix/processx.c:651 (processx_exec)

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/Linux/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Code
run(px, wd = tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! cannot start processx process '<path>/px' (system error 2, No such file or directory) @unix/processx.c:651 (processx_exec)

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/Linux/unix-sockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
conn_read_chars(sock1)
Condition
Error:
Error in `processx_conn_read_chars()`:
! ! Native call to `processx_connection_read_chars` failed
Caused by error in `chain_call(c_processx_connection_read_chars, con, n)` at connections.R:302:<col>:
! Cannot read from processx connection (system error 22, Invalid argument) @processx-connection.c:1891 (processx__connection_read)
Expand All @@ -13,21 +13,21 @@
Code
conn_create_unix_socket(sock)
Condition
Error:
Error in `conn_create_unix_socket()`:
! ! Native call to `processx_connection_create_socket` failed
Caused by error in `chain_call(c_processx_connection_create_socket, filename, encoding)` at connections.R:618:<col>:
! Server socket path too long: <tempdir>/<tempfile>
Code
conn_create_unix_socket("/dev/null")
Condition
Error:
Error in `conn_create_unix_socket()`:
! ! Native call to `processx_connection_create_socket` failed
Caused by error in `chain_call(c_processx_connection_create_socket, filename, encoding)` at connections.R:618:<col>:
! Cannot bind to socket (system error 98, Address already in use) @processx-connection.c:479 (processx_connection_create_socket)
Code
conn_connect_unix_socket("/dev/null")
Condition
Error:
Error in `conn_connect_unix_socket()`:
! ! Native call to `processx_connection_connect_socket` failed
Caused by error in `chain_call(c_processx_connection_connect_socket, filename, encoding)` at connections.R:640:<col>:
! Cannot connect to socket (system error 111, Connection refused) @processx-connection.c:550 (processx_connection_connect_socket)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/Windows/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
Code
process$new(tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! Command '<tempdir>/<tempfile>' not found @win/processx.c:1059 (processx_exec)

# working directory does not exist

Code
process$new(px, wd = tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! create process '<path>/px' (system error 267, The directory name is invalid.
) @win/processx.c:1370 (processx_exec)

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/Windows/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Code
run(px, wd = tempfile())
Condition
Error:
Error in `process_initialize()`:
! ! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, ...` at initialize.R:<line>:<col>:
Caused by error in `chain_call(...)` at initialize.R:<line>:<col>:
! create process '<path>/px' (system error 267, The directory name is invalid.
) @win/processx.c:1370 (processx_exec)

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/Windows/unix-sockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
conn_read_chars(sock1)
Condition
Error:
Error in `processx_conn_read_chars()`:
! ! Native call to `processx_connection_read_chars` failed
Caused by error in `chain_call(c_processx_connection_read_chars, con, n)` at connections.R:302:<col>:
! Cannot read from an un-accepted socket connection @processx-connection.c:1780 (processx__connection_read)
Expand Down
26 changes: 13 additions & 13 deletions tests/testthat/_snaps/err-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
7. global h() at script.R:13:10
8. global do() at script.R:14:10
9. processx:::chain_error(do2(), "Failed to base64 encode") at script.R:10:9
10. | base::withCallingHandlers({
10. | base::withCallingHandlers(...)
11. global do2()
12. processx:::chain_error(do3(), "something is wrong here") at script.R:7:9
13. | base::withCallingHandlers({
13. | base::withCallingHandlers(...)
14. global do3()
15. processx:::throw("because of this") at script.R:4:9
16. | base::signalCondition(cond)
Expand Down Expand Up @@ -121,10 +121,10 @@
7. global h() at script.R:15:14
8. global do() at script.R:16:14
9. processx:::chain_error(do2(), "Failed to base64 encode") at script.R:12:13
10. | base::withCallingHandlers({ ...
10. | base::withCallingHandlers(...)
11. global do2()
12. processx:::chain_error(do3(), "something is wrong here") at script.R:9:13
13. | base::withCallingHandlers({ ...
13. | base::withCallingHandlers(...)
14. global do3()
15. processx:::throw("because of this") at script.R:6:13
16. | base::signalCondition(cond)
Expand Down Expand Up @@ -157,13 +157,13 @@
7. global h() at script.R:12:10
8. global do() at script.R:13:10
9. processx:::chain_error(do2(), "Failed to base64 encode") at script.R:9:9
10. | base::withCallingHandlers({
10. | base::withCallingHandlers(...)
11. global do2()
12. processx:::chain_error(do3(), "something is wrong here") at script.R:6:9
13. | base::withCallingHandlers({
13. | base::withCallingHandlers(...)
14. global do3()
15. base::stop("because of this") at script.R:3:9
16. | base::.handleSimpleError(function (e)
16. | base::.handleSimpleError(...)
17. | local h(simpleError(msg, call))
18. | processx:::throw_error(err, parent = e)
19. | base::signalCondition(cond)
Expand Down Expand Up @@ -206,10 +206,10 @@
7. global h() at script.R:13:10
8. global do() at script.R:14:10
9. processx:::chain_error(do2(), "Failed to base64 encode") at script.R:10:9
10. | base::withCallingHandlers({ ...
10. | base::withCallingHandlers(...)
11. global do2()
12. processx:::chain_error(do3(), "something is wrong here") at script.R:7:9
13. | base::withCallingHandlers({ ...
13. | base::withCallingHandlers(...)
14. global do3()
15. rlang::abort("because of this") at script.R:4:9
16. | rlang:::signal_abort(cnd, .file)
Expand Down Expand Up @@ -253,9 +253,9 @@
3. | base::eval(ei, envir)
4. | base::eval(ei, envir)
5. processx:::chain_error(processx::run(px, c("return", "1")), "failed to run at script.R:4:5
6. | base::withCallingHandlers({
6. | base::withCallingHandlers(...)
7. processx::run(px, c("return", "1"))
8. processx:::throw(new_process_error(res, call = sys.call(), echo = echo,
8. processx:::throw(...)
9. | base::signalCondition(cond)
10. | (function (e)
11. | processx:::throw_error(err, parent = e)
Expand Down Expand Up @@ -291,9 +291,9 @@
3. | base::eval(ei, envir)
4. | base::eval(ei, envir)
5. processx:::chain_error(processx::run(px, c("return", "1")), "failed to r... at script.R:6:9
6. | base::withCallingHandlers({ ...
6. | base::withCallingHandlers(...)
7. processx::run(px, c("return", "1"))
8. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, ...
8. processx:::throw(...)
9. | base::signalCondition(cond)
10. | (function (e) ...
11. | processx:::throw_error(err, parent = e)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
cat(out$stderr)
Output
Error in `processx::run(processx:::get_tool("px"), c("errln", paste(1:20, ...` at script.R:2:5:
Error in `processx::run(...)` at script.R:2:5:
! System command 'px' failed
---
Exit status: 100
Expand Down Expand Up @@ -34,7 +34,7 @@
2. | base::withVisible(eval(ei, envir))
3. | base::eval(ei, envir)
4. | base::eval(ei, envir)
5. processx::run(processx:::get_tool("px"), c("errln", paste(1:20, at script.R:2:5
6. processx:::throw(new_process_error(res, call = sys.call(), echo = echo,
5. processx::run(...) at script.R:2:5
6. processx:::throw(...)
Execution halted

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/fifo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
Code
conn_create_fifo(read = TRUE, write = TRUE)
Condition
Error:
Error in `conn_create_fifo()`:
! ! Bi-directional FIFOs are not supported currently

---

Code
conn_connect_fifo(read = TRUE, write = TRUE)
Condition
Error:
Error in `conn_connect_fifo()`:
! ! Bi-directional FIFOs are not supported currently

Loading
Loading