Skip to content

Commit

Permalink
bot: raise ValueError instead of RuntimeError
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Dec 19, 2020
1 parent a12b8e6 commit 73d0aab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def has_channel_privilege(self, channel, privilege):
:param str channel: a channel the bot is in
:param int privilege: privilege level to check
:raise RuntimeError: when the channel is unknown
:raise ValueError: when the channel is unknown
This method checks the bot's privilege level in a channel, i.e. if it
has this level or higher privileges::
Expand All @@ -216,9 +216,10 @@ def has_channel_privilege(self, channel, privilege):
The ``channel`` argument can be either a :class:`str` or a
:class:`sopel.tools.Identifier`, as long as Sopel joined said channel.
If the channel is unknown, a :exc:`ValueError` will be raised.
"""
if channel not in self.channels:
raise RuntimeError('Unknown channel %s' % channel)
raise ValueError('Unknown channel %s' % channel)

return self.channels[channel].has_privilege(self.nick, privilege)

Expand Down
4 changes: 2 additions & 2 deletions test/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def test_has_channel_privilege_no_privilege(ircfactory, botfactory, tmpconfig):
name = Identifier('#adminchannel')

# unknown channel
with pytest.raises(RuntimeError):
with pytest.raises(ValueError):
sopel.has_channel_privilege('#adminchannel', plugin.VOICE)

# join channel
Expand All @@ -793,7 +793,7 @@ def test_has_channel_privilege_no_privilege(ircfactory, botfactory, tmpconfig):
assert not sopel.has_channel_privilege('#adminchannel', plugin.OPER)

# unknown channel
with pytest.raises(RuntimeError):
with pytest.raises(ValueError):
sopel.has_channel_privilege('#anotherchannel', plugin.VOICE)


Expand Down

0 comments on commit 73d0aab

Please sign in to comment.