stopOnError: Error Message Translator

Description Usage Arguments Value Examples

Description

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.

Usage

1
stopOnError(result, err_msg = "")

Arguments

result

return from a try() block

err_msg

custom error message

Value

Issues a stop() with an appropriate error message.

Examples

 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)

MazamaWebUtils documentation built on May 2, 2019, 2:41 a.m.