Skip to content

Commit 09fbc86

Browse files
committed
Check a restart exists before invoking it
1 parent 3113a95 commit 09fbc86

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: rlang
2-
Version: 0.4.0.9001
2+
Version: 0.4.0.9002
33
Title: Functions for Base Types and Core R and 'Tidyverse' Features
44
Description: A toolbox for working with base types, core R features
55
like the condition system, and core 'Tidyverse' features like tidy

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
# rlang (development)
33

4+
* `cnd_muffle()` now checks that a restart exists before invoking
5+
it. The restart might not exist if the condition is signalled with a
6+
different function (such as `stop(warning_cnd)`).
7+
48
* `trace_length()` returns the number of frames in a backtrace.
59

610
* Added internal utility `cnd_entrace()` to add a backtrace to a

R/cnd.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,17 @@ interrupt <- function() {
499499
#' my_particular_msg = calling(cnd_muffle)
500500
#' )
501501
cnd_muffle <- function(cnd) {
502-
switch(cnd_type(cnd),
503-
message = invokeRestart("muffleMessage"),
504-
warning = invokeRestart("muffleWarning"),
505-
interrupt = invokeRestart("resume"),
506-
invokeRestart("rlang_muffle")
502+
restart <- switch(cnd_type(cnd),
503+
message = "muffleMessage",
504+
warning = "muffleWarning",
505+
interrupt = "resume",
506+
"rlang_muffle"
507507
)
508508

509+
if (!is_null(findRestart(restart))) {
510+
invokeRestart(restart)
511+
}
512+
509513
abort("Can't find a muffling restart")
510514
}
511515

0 commit comments

Comments
 (0)