Source code for darc.error
# -*- coding: utf-8 -*-
"""Custom Exceptions
=======================
The :func:`~darc.error.render_error` function can be used to render
multi-line error messages with :mod:`stem.util.term` colours.
The :mod:`darc` project provides following custom exceptions:
* :exc:`~darc.error.LinkNoReturn`
* :exc:`~darc.error.UnsupportedLink`
* :exc:`~darc.error.UnsupportedPlatform`
* :exc:`~darc.error.UnsupportedProxy`
The :mod:`darc` project provides following custom exceptions:
* :exc:`~darc.error.TorBootstrapFailed`
* :exc:`~darc.error.I2PBootstrapFailed`
* :exc:`~darc.error.ZeroNetBootstrapFailed`
* :exc:`~darc.error.FreenetBootstrapFailed`
* :exc:`~darc.error.APIRequestFailed`
* :exc:`~darc.error.SiteNotFoundWarning`
* :exc:`~darc.error.LockWarning`
* :exc:`~darc.error.TorRenewFailed`
* :exc:`~darc.error.RedisCommandFailed`
"""
import stem.util.term
import darc.typing as typing
[docs]class LinkNoReturn(Exception):
"""The link has no return value from the hooks."""
[docs]class UnsupportedLink(Exception):
"""The link is not supported."""
[docs]class UnsupportedProxy(Exception):
"""The proxy is not supported."""
[docs]class TorBootstrapFailed(Warning):
"""Tor bootstrap process failed."""
[docs]class TorRenewFailed(Warning):
"""Tor renew request failed."""
[docs]class I2PBootstrapFailed(Warning):
"""I2P bootstrap process failed."""
[docs]class ZeroNetBootstrapFailed(Warning):
"""ZeroNet bootstrap process failed."""
[docs]class FreenetBootstrapFailed(Warning):
"""Freenet bootstrap process failed."""
[docs]class RedisCommandFailed(Warning):
"""Redis command execution failed."""
[docs]class DatabaseOperaionFailed(Warning):
"""Database operation execution failed."""
[docs]class APIRequestFailed(Warning):
"""API submit failed."""
[docs]class SiteNotFoundWarning(ImportWarning):
"""Site customisation not found."""
[docs]class LockWarning(Warning):
"""Failed to acquire Redis lock."""
[docs]def render_error(message: str, colour: typing.Color) -> str:
"""Render error message.
The function wraps the :func:`stem.util.term.format` function to
provide multi-line formatting support.
Args:
message: Multi-line message to be rendered with ``colour``.
colour (stem.util.term.Color): Front colour of text, c.f.
:class:`stem.util.term.Color`.
Returns:
The rendered error message.
"""
return ''.join(
stem.util.term.format(line, colour) for line in message.splitlines(True)
)