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

Exit hubot on unhandled promise rejections and other unrecoverable errors #172

Merged
merged 5 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changelog

in development
--------------
* Exit hubot on unhandled promise rejections and uncaught exceptions, usually caused by unrecoverable errors (bug fix)

0.9.3
-----
Expand Down
23 changes: 23 additions & 0 deletions scripts/stackstorm.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ var TWOFACTOR_MESSAGE = "This action requires two-factor auth! Waiting for your
module.exports = function(robot) {
slack_monkey_patch.patchSendMessage(robot);

// Makes the script crash on unhandled rejections instead of ignoring them and keep running.
// Usually happens when trying to connect to a nonexistent instances or similar unrecoverable issues.
// In the future Node.js versions, promise rejections that are not handled will terminate the process with a non-zero exit code.
process.on('unhandledRejection', function(err) {
throw err;
});

// Handle uncaught exceptions, log error and terminate hubot if one occurs
robot.error(function(err, res) {
if (err) {
robot.logger.error(err.stack || JSON.stringify(err));
}
if (res) {
res.send(JSON.stringify({
"status": "failed",
"msg": "An error occurred trying to post the message:\n" + err
}));
}

robot.logger.info('Hubot will shut down ...');
robot.shutdown();
});

var self = this;

var promise = Promise.resolve();
Expand Down