File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ Changelog
3
3
4
4
in development
5
5
--------------
6
+ * Exit hubot on unhandled promise rejections and uncaught exceptions, usually caused by unrecoverable errors (bug fix)
6
7
7
8
0.9.3
8
9
-----
Original file line number Diff line number Diff line change @@ -99,6 +99,29 @@ var TWOFACTOR_MESSAGE = "This action requires two-factor auth! Waiting for your
99
99
module . exports = function ( robot ) {
100
100
slack_monkey_patch . patchSendMessage ( robot ) ;
101
101
102
+ // Makes the script crash on unhandled rejections instead of ignoring them and keep running.
103
+ // Usually happens when trying to connect to a nonexistent instances or similar unrecoverable issues.
104
+ // In the future Node.js versions, promise rejections that are not handled will terminate the process with a non-zero exit code.
105
+ process . on ( 'unhandledRejection' , function ( err ) {
106
+ throw err ;
107
+ } ) ;
108
+
109
+ // Handle uncaught exceptions, log error and terminate hubot if one occurs
110
+ robot . error ( function ( err , res ) {
111
+ if ( err ) {
112
+ robot . logger . error ( err . stack || JSON . stringify ( err ) ) ;
113
+ }
114
+ if ( res ) {
115
+ res . send ( JSON . stringify ( {
116
+ "status" : "failed" ,
117
+ "msg" : "An error occurred trying to post the message:\n" + err
118
+ } ) ) ;
119
+ }
120
+
121
+ robot . logger . info ( 'Hubot will shut down ...' ) ;
122
+ robot . shutdown ( ) ;
123
+ } ) ;
124
+
102
125
var self = this ;
103
126
104
127
var promise = Promise . resolve ( ) ;
You can’t perform that action at this time.
0 commit comments