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 data is also written to the execution log. You can view it using the Yandex Cloud CLI or the management console
Examples of error handling
Case 1: user code goes outside the array boundaries, the non-numeric argument to binary operator
error is returned. The runtime environment captures the error and generates a JSON document that contains the error message (the errorMessage
field) and its type (the 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",
}