If an error occurs during the execution of a PHP function, Function Compute captures the error and returns a structured error response. Use the response body and HTTP header together to identify the failure cause and decide on next steps.
How it works
The following example throws a standard PHP exception:
<?php
function handler($event, $context) {
throw new Exception("oops");
}When you invoke this function, Function Compute returns a JSON response similar to:
{
"errorMessage": "oops",
"errorType": "Exception",
"stackTrace": {
"file": "/code/index.php",
"line": 3,
"traceString": ""
}
}The response fields are:
| Field | Description |
|---|---|
errorMessage | The exception message passed to the constructor |
errorType | The PHP exception class name |
stackTrace.file | The file path where the exception was thrown |
stackTrace.line | The line number where the exception was thrown |
stackTrace.traceString | A string representation of the stack trace |
In addition to the response body, the HTTP response includes the header X-Fc-Error-Type: UnhandledInvocationError, which signals that the invocation failed due to an unhandled exception in your function code.
What to do when an error occurs
When you receive X-Fc-Error-Type: UnhandledInvocationError:
Check
errorMessageanderrorTypein the response body to identify the exception.Review the function logs for the full stack trace and runtime context.
What's next
For the full list of error types that Function Compute can return, see the Error handling section of the Basics topic.