Skip to content

Commit

Permalink
Add InvalidData; Redo Exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
NCPlayz committed May 24, 2019
1 parent ad32210 commit 42185cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions discord/client.py
Expand Up @@ -1189,14 +1189,13 @@ async def fetch_channel(self, channel_id):

factory, ch_type = _channel_factory(data['type'])
if factory is None:
raise TypeError('Unknown channel type %s.' % data['type'])
raise InvalidData('Unknown channel type {type} for channel ID {id}.'.format_map(data))

if ch_type in (ChannelType.group, ChannelType.private):
channel = factory(me=self.user, data=data, state=self._connection)
else:
guild_id = int(data['guild_id'])
guild = self.get_guild(guild_id) or Object(id=guild_id)

channel = factory(guild=guild, state=self._connection, data=data)

return channel
Expand Down
6 changes: 6 additions & 0 deletions discord/errors.py
Expand Up @@ -125,6 +125,12 @@ class NotFound(HTTPException):
pass


class InvalidData(ClientException):
"""Exception that's raised when the library encounters unknown
or invalid data from Discord.
"""
pass

class InvalidArgument(ClientException):
"""Exception that's thrown when an argument to a function
is invalid some way (e.g. wrong value or wrong type).
Expand Down
3 changes: 2 additions & 1 deletion discord/guild.py
Expand Up @@ -32,6 +32,7 @@
from .member import Member, VoiceState
from .activity import create_activity
from .emoji import Emoji
from .errors import InvalidData
from .permissions import PermissionOverwrite
from .colour import Colour
from .errors import InvalidArgument, ClientException
Expand Down Expand Up @@ -955,7 +956,7 @@ async def fetch_channels(self):
def convert(d):
factory, ch_type = _channel_factory(d['type'])
if factory is None:
raise TypeError('Unknown channel type %s.' % d['type'])
raise InvalidData('Unknown channel type {type} for channel ID {id}.'.format_map(data))

channel = factory(guild=self, state=self._state, data=d)
return channel
Expand Down

0 comments on commit 42185cb

Please sign in to comment.