Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specific error messages no longer returned #228

Closed
jdblischak opened this issue Jun 16, 2022 · 2 comments
Closed

Specific error messages no longer returned #228

jdblischak opened this issue Jun 16, 2022 · 2 comments

Comments

@jdblischak
Copy link
Contributor

The recent updates to the error handling in the development versions of processx (r-lib/processx#335) and callr (#227) have broken some of my workflowr unit tests. My tests check for specific error messages, but these are no longer propagated via tryCatch(). Below is a reproducible example. Would it be possible to restore the previous behavior where the specific error message is retained?

f <- function() {
  tryCatch(
    callr::r_safe(function() stop("specific message")),
    error = function(e) e$message
  )
}

packageVersion("processx")
## [1] ‘3.6.0’
packageVersion("callr")
## [1] ‘3.7.0’
f()
## [1] "callr subprocess failed: specific message"

packageVersion("processx")
## [1] ‘3.6.0.9000’
packageVersion("callr")
## [1] ‘3.7.0.9000’
f()
## [1] "error in callr subprocess"
@gaborcsardi
Copy link
Member

You need to use conditionMessage() to query the message of a condition object:

f2 <- function() {
  tryCatch(
    callr::r_safe(function() stop("specific message")),
    error = function(e) conditionMessage(e)
  )
}
❯ cat(f2())
! error in callr subprocess
Caused by error in `(function () …`:
! specific message

@jdblischak
Copy link
Contributor Author

You need to use conditionMessage() to query the message of a condition object:

Confirmed. That fixed it. Thanks!

f2 <- function() {
  tryCatch(
    callr::r_safe(function() stop("specific message")),
    error = function(e) conditionMessage(e)
  )
}

packageVersion("processx")
## [1] ‘3.6.0’
packageVersion("callr")
## [1] ‘3.7.0’
f2()
## [1] "callr subprocess failed: specific message"

pak::pkg_install(c("r-lib/processx", "r-lib/callr"))

packageVersion("processx")
## [1] ‘3.6.0.9000’
packageVersion("callr")
## [1] ‘3.7.0.9000’
f2()
## [1] "! error in callr subprocess\nCaused by error in `(function () ...`:\n! specific message"
cat(f2())
## ! error in callr subprocess
## Caused by error in `(function () ...`:
## ! specific message

jdblischak added a commit to workflowr/workflowr that referenced this issue Jun 16, 2022
Motivated by change to error handling by processx/callr:

r-lib/callr#228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants