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

Log errors and exit on authentication issues on Hubot plugin initialization #168

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8f7c74e
Exit `st2chatop` from `st2client` failures.
jinpingh May 28, 2019
c2770bb
Call 'process.exit(1)' to exit from process.
jinpingh May 28, 2019
6613a3d
Add callback to handle uncaught hubot exceptions.
jinpingh May 31, 2019
fe44e13
Revert change made for `bind(self)`
jinpingh May 31, 2019
c3b451f
Add big comment to Slack monkey patcher
blag Jun 4, 2019
d44be18
Remove Object.assign() polyfill and require node.js >= 8.3.0
blag Jun 4, 2019
3bf6fe2
Break out the dummy Logger into its own module
blag Jun 4, 2019
51b0262
Accept robot_name parameter and save it
blag Jun 4, 2019
969c084
Rename st2client.js variables to api_client and auth_client
blag Jun 4, 2019
98cf5f2
Coalesce multiple var declarations into one
blag Jun 4, 2019
233915c
Combine and rename hubotErrorCallback and exitProcessWithLog into log…
blag Jun 4, 2019
0cf0e26
Refactor loadCommands to not have an options object parameter
blag Jun 4, 2019
28d2e4c
Ensure that we do not authenticate while the robot is stopping and sh…
blag Jun 4, 2019
76e7179
Use array unpacking because we can
blag Jun 4, 2019
f588845
Refactor stream error handle to properly register a callback
blag Jun 4, 2019
8518e92
Remove error handler now that we have an uncaughtException handler
blag Jun 4, 2019
52a4d0f
Rename 'source' to 'stream'
blag Jun 4, 2019
862a331
Close down the previous stream instead of recreating another one
blag Jun 4, 2019
b112859
Add unit tests for invalid auth environment variables
blag Jun 4, 2019
63abae1
Test for exit code
blag Jun 4, 2019
97f2ef9
Simplify Logger methods
blag Jun 4, 2019
b07c28f
Merge pull request #170 from StackStorm/issue-124/simplify-logger
blag Jun 4, 2019
189b2d0
Merge pull request #169 from StackStorm/issue-124/further-tweaks
blag Jun 4, 2019
2ccc85e
Relax assertions on calls to robot.logger.error
blag Jun 5, 2019
e6c5e01
Ignore the actual error string
blag Jun 6, 2019
df5a0db
Merge pull request #175 from StackStorm/issue-124/fix-bad-auth-test
blag Jun 6, 2019
1765c47
Merge branch 'master' into issue-124/exit_on_failures
blag Jun 6, 2019
7605f3c
The express response object is not a hubot response object, so don't …
blag Jun 6, 2019
0dcba8a
Don't exit on ST2 stream (EventSource) error, simply warn about the i…
blag Jun 6, 2019
f81eca6
Merge branch 'master' into issue-124/exit_on_failures
blag Jun 6, 2019
965ffb1
Try to warn the user if posting a message to the chat provider doesn'…
blag Jun 6, 2019
95a4434
Don't exit if loading commands from StackStorm fails
blag Jun 6, 2019
a5311e9
Move changelog line to in development section
blag Jun 6, 2019
c39ba0f
Tweak stop to completely restore previous behavior, and add a shutdow…
blag Jun 6, 2019
6a39dfb
Stop calling 'process.exit(1)` and change some logs
jinpingh Jun 6, 2019
9ac9aa7
Exit `st2chatops` from invalid ST2 configuration.
jinpingh Jun 7, 2019
9903e19
Checking authentication issue from hubot EventSource.
jinpingh Jun 10, 2019
5c86bfa
Move back authentication error check.
jinpingh Jun 10, 2019
6165f1e
Check `err.stack` before log stack information
jinpingh Jun 11, 2019
6d11ae2
Check more error messages for testcases.
jinpingh Jun 11, 2019
de756aa
Log the error message inside logErrorAndExit
jinpingh Jun 11, 2019
59147a6
Change spy function call for error messages.
jinpingh Jun 11, 2019
47639de
Take out two error messages to pass travis testing
jinpingh Jun 11, 2019
954ec13
Remove dead code
blag Jun 11, 2019
1432afd
Rename promise to something useful
blag Jun 11, 2019
e7e9d93
Since we retry anyway, reduce stream errors to warnings
blag Jun 12, 2019
f346581
Move init code to after function definitions
blag Jun 18, 2019
82b8fe6
Remove logErrorAndExit function
blag Jun 18, 2019
27523a0
Allow stopping the stream even when not shutting down hubot
blag Jun 18, 2019
7ee397f
Refactor to use promises properly
blag Jun 18, 2019
0b75e5b
Register globals for linters
blag Jun 18, 2019
68d3b9d
Add and update tests for new behavior
blag Jun 18, 2019
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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

in development
--------------
* st2chatops now gracefully exits on authentication failures and uncaught exceptions (improvement)
* code cleanup (improvement)

0.9.3
-----
Expand Down
31 changes: 0 additions & 31 deletions lib/slack-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,6 @@

var utils = require('./utils.js');

// Polyfill from:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
if (typeof Object.assign !== 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
if (target === null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}

var to = Object(target);

for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];

if (nextSource !== null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}

var buildMessagesWithChunkedFieldValue = function (msg) {
var msgs;

Expand Down
12 changes: 12 additions & 0 deletions lib/slack_monkey_patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ function patchSendMessage(robot) {
// formatted and parsed on the server side.
// NOTE / TODO: We can get rid of this nasty patch once our node-slack-client and hubot-slack pull
// requests are merged.
// This code was refactored in https://github.com/StackStorm/hubot-stackstorm/pull/6
// which was opened and merged by Kami on 2015-06-04.
// As of 2019-05-22, these were the PRs I could find for the node-slack-client
// hubot-slack repositories:
// * https://github.com/slackapi/node-slack-sdk/pull/42
// - which was closed during a refactor and converted into an issue:
// https://github.com/slackapi/node-slack-sdk/issues/138
// * https://github.com/slackapi/hubot-slack/pull/544
// - which was opened on 2018-11-14, which seems to be too late to actually
// apply to this code
// So...I'm not entirely sure this monkey patch is still necessary.
// End-to-end testing is required to figure out for sure.
if (robot.adapter && robot.adapter.constructor && robot.adapter.constructor.name === 'SlackBot') {
for (var channel in robot.adapter.client.channels) {
robot.adapter.client.channels[channel].sendMessage = sendMessageRaw.bind(robot.adapter.client.channels[channel]);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-string": "^1.5.0",
"eslint": "^5.16.0",
"eslint-plugin-notice": "0.7.8",
"gulp": "^3.9.1",
Expand All @@ -48,6 +49,7 @@
"hubot-help": "0.2.2",
"hubot-mock-adapter": "^1.1.1",
"log": "1.4.0",
"mocked-env": "^1.2.4",
"nock": "^10.0.0",
"nyc": "^13.0.1",
"sinon": "^6.3.5",
Expand Down
Loading