Skip to content
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

Allow to define custom handlers for uncaught exceptions. #229

Conversation

marshall-lee
Copy link

process.on('uncaughtException') and process.on('unhandledRejectoin')
handlers are suitable to do some final cleanup & send errors somewhere.

However, Functions Framework does non-graceful process.exit() so any
user-defined cleanup does not have a chance to finish.

So I propose to expose the ERROR_HANDLER to the user:

const framework = require('@google-cloud/functions-framework');
const origCallback = framework.ERROR_HANDLER.onUncaughtExceptionCallback;
framework.ERROR_HANDLER.onUncaughtExceptionCallback = (err) => {
  flush(timeout).then(() => origCallback(err));
};

@google-cla google-cla bot added the cla: yes label Oct 19, 2020
`process.on('uncaughtException')` and `process.on('unhandledRejectoin')`
handlers are suitable to do some final cleanup & send errors somewhere.

However, Functions Framework does non-graceful `process.exit()` so any
user-defined cleanup does not have a chance to finish.

So I propose to expose the `ERROR_HANDLER` to the user:

```javascript
const framework = require('@google-cloud/functions-framework');
const origCallback = framework.ERROR_HANDLER.onUncaughtExceptionCallback;
framework.ERROR_HANDLER.onUncaughtExceptionCallback = (err) => {
  flush(timeout).then(() => origCallback(err));
};
```
@grant
Copy link
Contributor

grant commented Oct 21, 2020

Thanks for the PR. I commented on the GitHub issue #215 (comment) with a suggested design and a prototype.

@grant
Copy link
Contributor

grant commented Nov 23, 2020

Closing in favor of the linked GitHub issue which needs an approved design.

@grant grant closed this Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants