Description
Current Behavior
If an exception is thrown in developer code, the functions framework leaves it unhandled.
functions-framework-php/src/CloudEventFunctionWrapper.php
Lines 62 to 63 in dba0a47
Assuming nowhere else in the Function Framework catches the exception, this will ultimately crash the FPM process. FPM error logging will probably handle that crash (and place in Error Logging), but the next request will incur cold start costs.
In addition to the crashing, this means developers do not have a mechanism to request a Pub/Sub retry without triggering a crash.
Expected Behavior
- Functions Framework catches the thrown exception, creates an HTTP 500 response, and logs the error.
- Exceptions do not crash the FPM process. If the developer wants to stop the container use
exit()
. - Logged error should align with the format for error grouping and lift to Cloud Error Reporting if possible
- X-Google-Status header is set to
error
. I'm not familiar with what this does, but see it in multiple frameworks. Maybe @grant has insight?
Other Language Implementations
Golang Implementation
Node.js can infer errors from callbacks and rejected promises in addition to thrown errors. On any error, set X-Google-Status header to 'error':
On thrown errors, send a crash response:
Node.js Implementation
Set X-Google-Status header to 'error' and return the error message: