diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-01-28 20:27:18 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-02-15 00:20:26 +0100 |
commit | 7facf153ac9f39d723882794775fd5392385ae6b (patch) | |
tree | 31499daa61931367a315ec1ad7f44f4a02175dff | |
parent | 3d6d3e3cc2b25cf3d888786b280561035374581b (diff) | |
download | wee-slack-7facf153ac9f39d723882794775fd5392385ae6b.tar.gz |
Print more useful error and debug messages on connection failure
-rw-r--r-- | wee_slack.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py index bea9ea3..2026390 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -375,9 +375,10 @@ class EventRouter(object): the data is valid JSON, add metadata, and place it back on the queue for processing as JSON. """ + team = self.teams[team_hash] try: # Read the data from the websocket associated with this team. - data = decode_from_utf8(self.teams[team_hash].ws.recv()) + data = decode_from_utf8(team.ws.recv()) message_json = json.loads(data) metadata = WeeSlackMetadata({ "team": team_hash, @@ -387,13 +388,17 @@ class EventRouter(object): self.record_event(message_json, 'type', 'websocket') self.receive_json(json.dumps(message_json)) except WebSocketConnectionClosedException: - self.teams[team_hash].set_disconnected() + w.prnt(team.channel_buffer, + 'Lost connection to slack team {} (on receive), reconnecting.'.format(team.domain)) + dbg('receive_ws_callback failed with exception:\n{}' + .format(traceback.format_exc()), level=5) + team.set_disconnected() return w.WEECHAT_RC_OK except ssl.SSLWantReadError: # Expected to happen occasionally on SSL websockets. return w.WEECHAT_RC_OK except Exception: - dbg("socket issue: {}\n".format(traceback.format_exc())) + dbg('socket issue:\n{}'.format(traceback.format_exc()), level=5) return w.WEECHAT_RC_OK def receive_httprequest_callback(self, data, command, return_code, out, err): @@ -1186,8 +1191,11 @@ class SlackTeam(object): # self.attach_websocket(ws) self.set_connected() self.connecting = False - except Exception as e: - dbg("websocket connection error: {}".format(decode_from_utf8(e))) + except: + w.prnt(self.channel_buffer, + 'Failed connecting to slack team {}, retrying.'.format(self.domain)) + dbg('connect failed with exception:\n{}' + .format(traceback.format_exc()), level=5) self.connecting = False return False else: @@ -1223,8 +1231,10 @@ class SlackTeam(object): self.ws.send(encode_to_utf8(message)) dbg("Sent {}...".format(message[:100])) except: - print "WS ERROR" - dbg("Unexpected error: {}\nSent: {}".format(sys.exc_info()[0], data)) + w.prnt(self.channel_buffer, + 'Lost connection to slack team {} (on send), reconnecting.'.format(self.domain)) + dbg('send_to_websocket failed with data: `{}` and exception:\n{}' + .format(message, traceback.format_exc()), level=5) self.set_disconnected() def update_member_presence(self, user, presence): |