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

include variable values in backtrace when known? #1676

Open
kevinushey opened this issue Dec 9, 2023 · 0 comments
Open

include variable values in backtrace when known? #1676

kevinushey opened this issue Dec 9, 2023 · 0 comments

Comments

@kevinushey
Copy link
Contributor

Consider something like:

> options(error = rlang::entrace)
> x <- "/tmp/no/such/file"
> local({
+   readLines(x)
+ })
Error in file(con, "r") : 
  (converted from warning) cannot open file '/tmp/no/such/file': No such file or directory
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error:
! No such file or directory
---
Backtrace:
    ▆
 1. ├─base::local(...)
 2. │ └─base::eval.parent(substitute(eval(quote(expr), envir)))
 3. │   └─base::eval(expr, p)
 4. │     └─base::eval(expr, p)
 5. └─base::eval(...)
 6.   └─base::eval(...)
 7.     └─base::readLines(x)
 8.       └─base::file(con, "r")

Would it be possible for rlang to include "scalar" values for parameters in these error traces, so that we could get something like:

Backtrace:
    ▆
 1. ├─base::local(...)
 2. │ └─base::eval.parent(substitute(eval(quote(expr), envir)))
 3. │   └─base::eval(expr, p)
 4. │     └─base::eval(expr, p)
 5. └─base::eval(...)
 6.   └─base::eval(...)
 7.     └─base::readLines(x@"/tmp/no/such/file")
 8.       └─base::file(con, "r")

(Not sure if there's a more appropriate syntax for values presented in this way)


Motivation; it would help in diagnosing backtraces like this:

== Failed tests ================================================================
-- Error ('test-update.R:7:3'): update() finds packages requiring updates from CRAN --
Error in `file(con, "rb")`: cannot open the connection
Backtrace:
     x
  1. \-renv::init() at test-update.R:7:3
  2.   \-renv:::renv_init_fini(project, profile, load, restart) at renv/R/init.R:152:3
  3.     \-renv:::renv_activate_impl(...) at renv/R/init.R:158:3
  4.       \-renv::load(project) at renv/R/activate.R:92:5
  5.         \-renv:::renv_load_minimal(project) at renv/R/load.R:99:3
  6.           \-renv:::renv_load_finish(project, lockfile) at renv/R/load.R:[204](https://github.com/rstudio/renv/actions/runs/7148982902/job/19470660872#step:6:206):3
  7.             \-renv:::renv_load_report_synchronized(project, lockfile) at renv/R/load.R:756:3
  8.               \-(function() {... at renv/R/load.R:853:3
  9.                 \-renv::status(project = project, sources = FALSE) at renv/R/load.R:856:5
 10.                   \-renv:::renv_lockfile_create(...) at renv/R/status.R:147:3
 11.                     +-base::withRestarts(...) at renv/R/lockfile.R:186:3
 12.                     | \-base (local) withOneRestart(expr, restarts[[1L]])
 13.                     |   \-base (local) doWithOneRestart(return(expr), restart)
 14.                     \-renv:::renv_lockfile_create_impl(...) at renv/R/lockfile.R:186:3
 15.                       \-renv:::renv_snapshot_packages(...) at renv/R/lockfile.R:[207](https://github.com/rstudio/renv/actions/runs/7148982902/job/19470660872#step:6:209):3
 16.                         \-renv:::map(paths, renv_snapshot_description) at renv/R/snapshot.R:1057:3
 17.                           \-base::lapply(x, f, ...) at renv/R/utils-map.R:57:3
 18.                             \-renv (local) FUN(X[[i]], ...)
 19.                               \-renv:::renv_description_read(path, package) at renv/R/snapshot.R:705:3
 20.                                 \-renv:::filebacked(...) at renv/R/description.R:26:3
 21.                                   \-renv (local) callback(path, ...) at renv/R/filebacked.R:95:3
 22.                                     \-renv:::renv_dcf_read(path, ...) at renv/R/description.R:75:3
 23.                                       +-text %||% renv_dcf_read_impl(file, ...) at renv/R/dcf.R:9:3
 24.                                       \-renv:::renv_dcf_read_impl(file, ...) at renv/R/dcf.R:9:3
 25.                                         \-base::readBin(file, what = "raw", n = 8192L) at renv/R/dcf.R:88:3
 26.                                           \-base::file(con, "rb")
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

1 participant