ensurer icon indicating copy to clipboard operation
ensurer copied to clipboard

Added error-handling for piping

Open williFiebranz opened this issue 9 years ago • 2 comments

Changed default behavior of error handling in two ways:

  1. fail_with default is now try(stop(e))
  2. if class(.value) == ‚try-error‘ return .value immediately

williFiebranz avatar Jun 11 '15 21:06 williFiebranz

Problem is that ensure would no longer "ensure" by default:

get_important_message %>% # suppose this fails, maybe the result is say, `FALSE`
  ensure_that(is.character) %>% 
  send_message

Since try-errors actually pass is.character you could end up sending the error in this example. Even though this is a pseudo-example it shows that ensure did not ensure that get_important_message got a character message before allowing control to be handed over to send_message, which may send an error rather than the message.

smbache avatar Jun 12 '15 13:06 smbache

Also, in your example, why not just have both conditions in one call to ensure rather than chaining them. The latter option is really meant to be used when you don't want to check this before knowing that the previous call passed.

smbache avatar Jun 12 '15 13:06 smbache