Python function error handling
Written by
Updated at October 9, 2023
If a handler reports a Python function runtime or loading error, the runtime environment automatically captures the error and returns a JSON document with details of the error type, text, and location 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
Example of error handling
Function code:
def handler(event, context):
return unknownVariable
JSON document returned:
{
"errorMessage": "name 'unknownVariable' is not defined",
"errorType": "NameError",
"stackTrace": [
" File \"/function/runtime/runtime.py\", line 155, in handle_event\n result = h(r.event, r.context)\n",
" File \"/function/code/main.py\", line 2, in handler\n return unknownVariable\n"
]
}