[Rd] message(<cond>) and warning(<cond>) circumvent calling handlers and signal the original class, e.g. an error
r-deve| @end|ng |rom @ker@t|ng@de
Tue Mar 1 20:05:27 CET 2022
There is the same issue with stop():
> w <- simpleWarning("careful")
> tryCatch(stop(w), condition = identity)
I very recently stumbled upon this, when a warning was re-raised as an error, which was then not caught by an outer try():
+ tryCatch(warning("careful"), warning = function(w) stop(w)),
+ silent = TRUE
Error in doTryCatch(return(expr), name, parentenv, handler) : careful
I would also like to see this behavior changed. I think that stop() should always signal an error, warning() a warning and message() a message.
2022-03-01 19:38 GMT+01:00 "Henrik Bengtsson" <henrik.bengtsson using gmail.com>:
> Hi, in help("message", package = "base"), we can read:
> Description: 'message' is used for generating 'simple' diagnostic
> messages which are neither warnings nor errors, but nevertheless
> represented as conditions.
> From this, I conclude that message() should generate a condition that
> are neither warning nor errors.
> However, the following signals a condition of class 'error':
>> e <- simpleError("boom!\n")
> This can be seen if we do:
>> res <- tryCatch(message(e), condition = identity)
> <simpleError: boom!
> This stems from message(e) using signalCondition(e) internally.
> Another problem with this behavior is that message(e) cannot be suppressed:
> or captured with calling handlers, e.g.
>> res <- withCallingHandlers(message(e), condition = identity)
> If we replace e <- simpleError("boom") with e <-
> simpleWarning("careful"), we see a similar behavior. These problems
> exist also with warning(e). The current behaviors prevent functions
> from capturing and relaying message(<error>), message(<warning>), and
> I'm happy to post a bug report to <https://bugs.r-project.org/>.
> PS. BTW, it looks like some recent "..." tweaks to the warning() and
> stop() code could be applied also to message().
> R-devel using r-project.org mailing list
More information about the R-devel