R function error handling
If a handler reports a R function runtime or loading error, the runtime environment automatically captures the error and returns a JSON document with the error type in the response. For more information about the JSON document format, see Calling a function.
The error info is also written to the execution log. You can view the log via the Yandex Cloud CLI or the management console
Examples of error handling
Case 1: User code goes outside the array boundaries, resulting in non-numeric argument to binary operator
. The runtime environment intercepts the exception and generates a JSON document stating the error message (errorMessage
field) and error type (errorType
field).
Function code:
handler <-function() {
return(paste0('{"result":"', "1" + 2,'"}'))
}
JSON document returned:
{
"errorMessage": "Error in a + b: non-numeric argument to binary operator\n",
"errorType": "simpleError",
}
Case 2: User code indicates an error by throwing
Function code:
handler <- function() {
stop("Some error message")
}
JSON document returned:
{
"errorMessage": "Error in handler(): Some error message\n",
"errorType": "simpleError",
}