Skip to content

Commit

Permalink
indicate to rlang top env for trimmed traceback
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv committed Dec 20, 2024
1 parent 880b664 commit c9d7a69
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 57 deletions.
5 changes: 5 additions & 0 deletions R/evaluate.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ evaluate <- function(input,
}
local_inject_funs(envir)

if (is.null(getOption("rlang_trace_top_env"))) {
# If not already set, indicate the top environment to trim traceback
options(rlang_trace_top_env = envir)
}

# Handlers for warnings, errors and messages
user_handlers <- output_handler$calling_handlers
evaluate_handlers <- condition_handlers(
Expand Down
25 changes: 5 additions & 20 deletions tests/testthat/_snaps/conditions/abort-error.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
Error in `h()`:
! !
Backtrace:
1. ├─evaluate::evaluate(...)
2. │ ├─base::withRestarts(...)
3. │ │ └─base (local) withRestartList(expr, restarts)
4. │ │ ├─base (local) withOneRestart(withRestartList(expr, restarts[-nr]), restarts[[nr]])
5. │ │ │ └─base (local) doWithOneRestart(return(expr), restart)
6. │ │ └─base (local) withRestartList(expr, restarts[-nr])
7. │ │ └─base (local) withOneRestart(expr, restarts[[1L]])
8. │ │ └─base (local) doWithOneRestart(return(expr), restart)
9. │ ├─evaluate:::with_handlers(...)
10. │ │ ├─base::eval(call)
11. │ │ │ └─base::eval(call)
12. │ │ └─base::withCallingHandlers(...)
13. │ ├─base::withVisible(eval(expr, envir))
14. │ └─base::eval(expr, envir)
15. │ └─base::eval(expr, envir)
16. └─global f()
17. └─global g()
18. └─global h()
19. └─rlang::abort("!")
1. └─global f()
2. └─global g()
3. └─global h()
4. └─rlang::abort("!")
Execution halted
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
Error in `h()`:
! !
Backtrace:
1. ├─evaluate::evaluate(...)
2. │ ├─base::withRestarts(...)
3. │ │ └─base (local) withRestartList(expr, restarts)
4. │ │ ├─base (local) withOneRestart(withRestartList(expr, restarts[-nr]), restarts[[nr]])
5. │ │ │ └─base (local) doWithOneRestart(return(expr), restart)
6. │ │ └─base (local) withRestartList(expr, restarts[-nr])
7. │ │ └─base (local) withOneRestart(expr, restarts[[1L]])
8. │ │ └─base (local) doWithOneRestart(return(expr), restart)
9. │ ├─evaluate:::with_handlers(...)
10. │ │ ├─base::eval(call)
11. │ │ │ └─base::eval(call)
12. │ │ └─base::withCallingHandlers(...)
13. │ ├─base::withVisible(eval(expr, envir))
14. │ └─base::eval(expr, envir)
15. │ └─base::eval(expr, envir)
16. └─global f()
17. └─global g()
18. └─global h()
1. └─global f()
2. └─global g()
3. └─global h()
Execution halted
20 changes: 2 additions & 18 deletions tests/testthat/_snaps/conditions/stop-error-trace-wch.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
Error in `g()`:
! could not find function "g"
Backtrace:
1. ├─base::withCallingHandlers(...)
2. ├─evaluate::evaluate(...)
3. │ ├─base::withRestarts(...)
4. │ │ └─base (local) withRestartList(expr, restarts)
5. │ │ ├─base (local) withOneRestart(withRestartList(expr, restarts[-nr]), restarts[[nr]])
6. │ │ │ └─base (local) doWithOneRestart(return(expr), restart)
7. │ │ └─base (local) withRestartList(expr, restarts[-nr])
8. │ │ └─base (local) withOneRestart(expr, restarts[[1L]])
9. │ │ └─base (local) doWithOneRestart(return(expr), restart)
10. │ ├─evaluate:::with_handlers(...)
11. │ │ ├─base::eval(call)
12. │ │ │ └─base::eval(call)
13. │ │ └─base::withCallingHandlers(...)
14. │ ├─base::withVisible(eval(expr, envir))
15. │ └─base::eval(expr, envir)
16. │ └─base::eval(expr, envir)
17. └─global f()
1. └─global f()
Execution halted

0 comments on commit c9d7a69

Please sign in to comment.