Skip to content

Allow to define custom handlers for uncaught exceptions. - #229

Closed
marshall-lee wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
marshall-lee:custom-uncaught-exception-handler
Closed

marshall-lee wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
marshall-lee:custom-uncaught-exception-handler

Conversation

@marshall-lee

Copy link
Copy Markdown

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

grant commented Oct 21, 2020

Copy link
Copy Markdown
Contributor

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

@grant

grant commented Nov 23, 2020

Copy link
Copy Markdown
Contributor

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.

2 participants