-
Notifications
You must be signed in to change notification settings - Fork 38
feat: add better handling for exceptions #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
throw new \LogicException( | ||
'Function response must be string or ' . ResponseInterface::class | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the increased certainty this provides. Good idea!
'Invalid signature type: "%s"', $signatureType)); | ||
} | ||
$this->errorLogFunc = function (string $error) { | ||
fwrite(fopen('php://stderr', 'wb'), json_encode([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this error also get routed to Error Reporting on Cloud Functions? (Sending further context in chat.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope so!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to manually test. If it doesn't work, we might not want to make the change.
src/Invoker.php
Outdated
: 'error'; | ||
return new Response(200, [ | ||
FunctionWrapper::FUNCTION_STATUS_HEADER => $statusHeader, | ||
], $e->getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message might surface implementation details of the function, maybe it should respect display_errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I am also okay omitting it to be safe. I was following Node's implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the error from the response for simplicity for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except I think we need to clarify the Error Reporting compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per further discussion, the error reporting consideration doesn't seem like a blocker.
See #60
The invoker catches all throwables of type
Exception
(note:Error
types are not handled).The invoker then sets:
200
X-Google-Status
response header to "error" (cloudevent) or "crash" (http)The invoker logs an error to
stderr
with a json-formatted stack trace.Other notes:
LogicException