raise exceptions instead of logging, so we get a helpful traceback

This commit is contained in:
Valentin Lorentz 2021-03-13 12:22:39 +01:00
parent c7939d3eb5
commit 99a6a7cde9

View File

@ -1345,29 +1345,33 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
-- <https://ircv3.net/specs/extensions/multiline> -- <https://ircv3.net/specs/extensions/multiline>
""" """
if not conf.supybot.protocols.irc.experimentalExtensions(): if not conf.supybot.protocols.irc.experimentalExtensions():
log.error('queueBatch is disabled because it depends on draft ' raise ValueError(
'IRC specifications. If you know what you are doing, ' 'queueBatch is disabled because it depends on draft '
'set supybot.protocols.irc.experimentalExtensions.') 'IRC specifications. If you know what you are doing, '
return 'set supybot.protocols.irc.experimentalExtensions.')
if len(msg) < 2: if len(msg) < 2:
log.error('queueBatch called with less than two messages.') raise ValueError(
return 'queueBatch called with less than two messages.')
if msgs[0].command.upper() != 'BATCH' or msgs[0].args[0][0] != '+': if msgs[0].command.upper() != 'BATCH' or msgs[0].args[0][0] != '+':
log.error('queueBatch called with non-"BATCH +" as first message.') raise ValueError(
return 'queueBatch called with non-"BATCH +" as first message.')
if msgs[-1].command.upper() != 'BATCH' or msgs[-1].args[0][0] != '-': if msgs[-1].command.upper() != 'BATCH' or msgs[-1].args[0][0] != '-':
log.error('queueBatch called with non-"BATCH -" as last message.') raise ValueError(
return 'queueBatch called with non-"BATCH -" as last message.')
batch_name = msgs[0].args[0][1:] batch_name = msgs[0].args[0][1:]
if msgs[0].args[0][1:] != batch_name: if msgs[0].args[0][1:] != batch_name:
log.error('queueBatch called with mismatched BATCH name args.') raise ValueError(
return 'queueBatch called with mismatched BATCH name args.')
if any(msg.server_tags.get('batch') != batch_name for msg in msgs): if any(msg.server_tags.get('batch') != batch_name for msg in msgs):
log.error('queueBatch called with mismatched batch names.') raise ValueError(
'queueBatch called with mismatched batch names.')
return return
if batch_name in self._queued_batches: if batch_name in self._queued_batches:
log.error('queueBatch called with a batch name already in flight') raise ValueError(
return 'queueBatch called with a batch name already in flight')
self._queued_batches[batch_name] = msgs self._queued_batches[batch_name] = msgs
# Enqueue only the start of the batch. When takeMsg sees it, it will # Enqueue only the start of the batch. When takeMsg sees it, it will