GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-php
Handle Thrown Exceptions
- Dominant language
- PHP
- Stars
- 213
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
### Current Behavior
If an exception is thrown in developer code, the functions framework leaves it unhandled.
https://github.com/GoogleCloudPlatform/functions-framework-php/blob/dba0a47f0fe0f2563d5475194108ec1bf1f4918a/src/CloudEventFunctionWrapper.php#L62-L63
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':
https://github.com/GoogleCloudPlatform/functions-framework-go/blob/fed357741a8521eeeaad9b32dc140d69ea69626c/funcframework/framework.go#L207
On thrown errors, send a crash response:
https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/01b7df3128cd5c6b736aa0c6cedb35e53a3e92ad/src/invoker.ts#L247-283
https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/01b7df3128cd5c6b736aa0c6cedb35e53a3e92ad/src/logger.ts#L25-52
#### Node.js Implementation
Set X-Google-Status header to 'error' and return the error message:
https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/01b7df3128cd5c6b736aa0c6cedb35e53a3e92ad/src/invoker.ts#L65-72
Contributor guide
Assessment
This issue has not been assessed yet.