smbache / ensurer

Ensure values are as expected at runtime
Other
84 stars 4 forks source link

Added error-handling for piping #14

Open williFiebranz opened 9 years ago

williFiebranz commented 9 years ago

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
smbache commented 9 years ago

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 commented 9 years ago

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.