GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-php

Handle Thrown Exceptions

Aperta
#60 5 commenti 0 reazioni 1 assegnatario Rivendicata da @bshaffer Vedi su GitHub
bug P2
Lingua principale
PHP
Stelle
213
Fork
37
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.