Description Usage Arguments Value Examples
When writing R code to be used in production systems that work
with user supplied input, it is important to enclose chunks of code inside
of a try()
block. It is equally important to generate error log
messages that can be found and understood during an autopsy when something
fails
At Mazama Science we have our own internal standard for how to do error handling in a manner that allows os to quickly navigate to the source of errors in a production system.
The example section contains a snippet of how we use this function.
1 | stopOnError(result, err_msg = "")
|
result |
return from a |
err_msg |
custom error message |
Issues a stop()
with an appropriate error message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ## Not run:
logger.setup()
# Arbitrarily deep in the stack we might have:
myFunc <- function(x) {
a <- log(x)
}
userInput <- 10
result <- try({
myFunc(x=userInput)
}, silent=TRUE)
stopOnError(result)
userInput <- "ten"
result <- try({
myFunc(x=userInput)
}, silent=TRUE)
stopOnError(result)
result <- try({
myFunc(x=userInput)
}, silent=TRUE)
stopOnError(result, "Unable to process user input")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.