Skip to content
Prev 60540 / 63421 Next

[External] Re: message(<cond>) and warning(<cond>) circumvent calling handlers and signal the original class, e.g. an error

Thank you, Luke.  I discovered this problem last year, where a user
reported that their use of message(<error>) in futures would not work
the same way as without futures. The issue is that the future
framework captures the error condition and relays it, rather than
outputting the message string, which happens if you don't capture the
error condition. Today there was another similar report from another
package using futures. They both had in common that they use

res <- tryCatch({
  some_fcn(x)
}, error = function(e) {
  message(e)
  NA
})

to return a missing value on errors, while outputting the error
message string to inform the user on the error.  I've been informing
them to instead use

  message(conditionMessage(e))

in this case. Your reply confirms this, and I can now confidently say
that using message(e) is incorrect here.

I think the help pages on message, warning, and stop could be more
explicit on this behavior.

My preference would be that it is an error if calling message(cond)
with !inherits(cond, "message"), calling warning(cond) with
!inherits(cond, "warning"), and stop(cond) with !inherits(cond,
"error").  But, maybe there are valid arguments for allowing such use
cases.

Thanks,

Henrik
On Tue, Mar 1, 2022 at 3:12 PM <luke-tierney at uiowa.edu> wrote: