From 4483f42e4ff0c77480da2891e32baaaf02911f06 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 10 Jul 2024 16:06:49 +0200 Subject: [PATCH] Strip call for top-level errors --- R/conditions.R | 4 ++++ tests/testthat/test-conditions.R | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/R/conditions.R b/R/conditions.R index 18e5a64e..dee08f0e 100644 --- a/R/conditions.R +++ b/R/conditions.R @@ -54,5 +54,9 @@ sanitize_call <- function(cnd) { if (identical(cnd$call, quote(withVisible(do)))) { cnd$call <- NULL } + if (identical(cnd$call, quote(eval(as.call(list(cb)), envir)))) { + cnd$call <- NULL + } + cnd } diff --git a/tests/testthat/test-conditions.R b/tests/testthat/test-conditions.R index f760d835..abaf6d21 100644 --- a/tests/testthat/test-conditions.R +++ b/tests/testthat/test-conditions.R @@ -16,6 +16,10 @@ test_that("all condition handlers first capture output", { test_that("conditions get calls stripped", { expect_equal(evaluate("warning('x')")[[2]]$call, NULL) expect_equal(evaluate("stop('x')")[[2]]$call, NULL) + + # including errors emitted by C + expect_equal(evaluate("mpg")[[2]]$call, NULL) + expect_equal(evaluate("3()")[[2]]$call, NULL) }) test_that("envvar overrides keep_* arguments", {