Victor Vasiliev has submitted this change and it was merged.
Change subject: Improve error handling.
......................................................................
Improve error handling.
Change-Id: I13f7949e220c966b40d72a473a35861128d07914
---
M rcsub.py
1 file changed, 13 insertions(+), 3 deletions(-)
Approvals:
Victor Vasiliev: Verified; Looks good to me, approved
diff --git a/rcsub.py b/rcsub.py
index ccd93df..4aa4b89 100644
--- a/rcsub.py
+++ b/rcsub.py
@@ -41,6 +41,8 @@
def subscribe(self, channel):
if len(self.channels) >= config['max_channels']:
raise ProtocolError('Exceeded maximum subscription limit of %i
channels' % config['max_channels'])
+ if channel in self.channels:
+ raise ProtocolError('You are already subscribed to the channel %s'
% channel)
self.channels.append(channel)
router.subscribe(channel, self)
@@ -66,6 +68,9 @@
if '@' not in command:
raise ProtocolError('No command specified')
+ if command['@'] in ('subscribe', 'unsubscribe') and 'channel' not in
command:
+ raise ProtocolError('No channel specified')
+
if command['@'] == 'subscribe':
self.subscribe(command['channel'])
return { "@" : "success" }
@@ -81,6 +86,12 @@
class ProtocolError(Exception):
pass
+
+def handleError(err):
+ if type(err) in (ProtocolError, ValueError):
+ return str(err)
+ else:
+ return "Internal error"
class MediaWikiRCInput(DatagramProtocol):
def datagramReceived(self, data, (host, port)):
@@ -102,7 +113,7 @@
try:
self.message( self.subscriber.handleJSONCommand(data) )
except Exception as err:
- self.message({'@' : 'error'})
+ self.message({'@' : 'error', 'message' : handleError(err)})
def deliver(self, message):
self.message(message)
@@ -120,10 +131,9 @@
def lineReceived(self, line):
try:
- print line
self.message( self.subscriber.handleJSONCommand(line) )
except Exception as err:
- self.message({'@' : 'error'})
+ self.message({'@' : 'error', 'message' : handleError(err)})
def deliver(self, message):
self.message(message)
--
To view, visit https://gerrit.wikimedia.org/r/52958
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I13f7949e220c966b40d72a473a35861128d07914
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/rcsub
Gerrit-Branch: master
Gerrit-Owner: Victor Vasiliev <[email protected]>
Gerrit-Reviewer: Victor Vasiliev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits