All Products
Search
Document Center

Function Compute (2.0):Error handling

Last Updated:Apr 09, 2024

This topic describes how to handle errors in the Python runtime environment.

If an error occurs when you execute a function, Function Compute captures the error and returns the error information. The following sample code provides an example:

def handler(event, context):
    raise Exception('something is wrong')

When an error occurs, the HTTP header in the response to the function invocation contains X-Fc-Error-Type: UnhandledInvocationError. The HTTP request body contains the following information. For more information about the error types in Function Compute, see Error handling.

{
  "errorMessage": "something is wrong",
  "errorType": "Exception",
  "stackTrace": [
    [
      "File \"/code/index.py\"",
      "line 2",
      "in my_handler",
      "raise Exception('something is wrong')"
    ]
  ]
}

The following table describes the fields in the error information.

Field

Type

Description

errorMessage

String

The error message.

errorType

String

The error type.

stackTrace

List

The stack of the error.