Skip to content

Commit

Permalink
Add exception hierarchy to the documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Mar 12, 2019
1 parent e15b4ef commit 13b2396
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
15 changes: 15 additions & 0 deletions docs/_static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ div.helpful > p.admonition-title:after {
content: unset;
}

/* exception hierarchy */

.exception-hierarchy-content dd,
.exception-hierarchy-content dl {
margin: 0px 2px;
}

.exception-hierarchy-content {
margin-left: 0.5em;
}

.exception-hierarchy-content ul {
list-style: '»' !important;
}

pre {
background-color: #f5f5f5;
border: 1px solid #C6C9CB;
Expand Down
17 changes: 17 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2196,3 +2196,20 @@ The following exceptions are thrown by the library.
.. autoexception:: discord.opus.OpusError

.. autoexception:: discord.opus.OpusNotLoaded

Exception Hierarchy
~~~~~~~~~~~~~~~~~~~~~

.. exception_hierarchy::

- :exc:`Exception`
- :exc:`DiscordException`
- :exc:`ClientException`
- :exc:`NoMoreItems`
- :exc:`GatewayNotFound`
- :exc:`HTTPException`
- :exc:`Forbidden`
- :exc:`NotFound`
- :exc:`InvalidArgument`
- :exc:`LoginFailure`
- :exc:`ConnectionClosed`
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinxcontrib.asyncio',
'details'
'details',
'exception_hierarchy'
]

autodoc_member_order = 'bysource'
Expand Down
26 changes: 24 additions & 2 deletions docs/ext/commands/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ Converters

.. _ext_commands_api_errors:

Errors
-------
Exceptions
-----------

.. autoexception:: discord.ext.commands.CommandError
:members:
Expand Down Expand Up @@ -265,3 +265,25 @@ Errors
.. autoexception:: discord.ext.commands.BotMissingPermissions
:members:

Exception Hierarchy
+++++++++++++++++++++

.. exception_hierarchy::

- :exc:`~.DiscordException`
- :exc:`~.commands.CommandError`
- :exc:`~.commands.ConversionError`
- :exc:`~.commands.UserInputError`
- :exc:`~.commands.MissingRequiredArgument`
- :exc:`~.commands.TooManyArguments`
- :exc:`~.commands.BadArgument`
- :exc:`~.commands.BadUnionArgument`
- :exc:`~.commands.CommandNotFound`
- :exc:`~.commands.CheckFailure`
- :exc:`~.commands.NoPrivateMessage`
- :exc:`~.commands.NotOwner`
- :exc:`~.commands.MissingPermissions`
- :exc:`~.commands.BotMissingPermissions`
- :exc:`~.commands.DisabledCommand`
- :exc:`~.commands.CommandInvokeError`
- :exc:`~.commands.CommandOnCooldown`
27 changes: 27 additions & 0 deletions docs/extensions/exception_hierarchy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from docutils.parsers.rst import Directive
from docutils.parsers.rst import states, directives
from docutils.parsers.rst.roles import set_classes
from docutils import nodes
from sphinx.locale import _

class exception_hierarchy(nodes.General, nodes.Element):
pass

def visit_exception_hierarchy_node(self, node):
self.body.append(self.starttag(node, 'div', CLASS='exception-hierarchy-content'))

def depart_exception_hierarchy_node(self, node):
self.body.append('</div>\n')

class ExceptionHierarchyDirective(Directive):
has_content = True

def run(self):
self.assert_has_content()
node = exception_hierarchy('\n'.join(self.content))
self.state.nested_parse(self.content, self.content_offset, node)
return [node]

def setup(app):
app.add_node(exception_hierarchy, html=(visit_exception_hierarchy_node, depart_exception_hierarchy_node))
app.add_directive('exception_hierarchy', ExceptionHierarchyDirective)

0 comments on commit 13b2396

Please sign in to comment.