Source code for darc.error

# -*- coding: utf-8 -*-
"""Custom Exceptions
=======================

The :mod:`darc` project provides following custom exceptions:

* :exc:`~darc.error.LinkNoReturn`
* :exc:`~darc.error.UnsupportedLink`
* :exc:`~darc.error.UnsupportedPlatform`
* :exc:`~darc.error.UnsupportedProxy`
* :exc:`~darc.error.WorkerBreak`

.. note::

   All exceptions are inherited from :exc:`~darc.error._BaseException`.

The :mod:`darc` project provides following custom warnings:

* :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`
* :exc:`~darc.error.HookExecutionFailed`

.. note::

   All warnings are inherited from :exc:`~darc.error._BaseWarning`.

"""

[docs]class _BaseException(Exception): """Base exception class for :mod:`darc` module."""
[docs]class LinkNoReturn(_BaseException): """The link has no return value from the hooks. Args: link (darc.link.Link): Original link object. Keyword Args: drop: If drops the ``link`` from task queues. """
[docs] def __init__(self, link=None, *, drop: bool = True) -> None: # type: ignore[no-untyped-def] self.link = link self.drop = drop super().__init__()
[docs]class UnsupportedPlatform(_BaseException): """The platform is not supported."""
[docs]class UnsupportedProxy(_BaseException): """The proxy is not supported."""
[docs]class WorkerBreak(_BaseException): """Break from the worker loop."""
[docs]class _BaseWarning(Warning): """Base warning for :mod:`darc` module."""
[docs]class TorBootstrapFailed(_BaseWarning): """Tor bootstrap process failed."""
[docs]class TorRenewFailed(_BaseWarning): """Tor renew request failed."""
[docs]class I2PBootstrapFailed(_BaseWarning): """I2P bootstrap process failed."""
[docs]class ZeroNetBootstrapFailed(_BaseWarning): """ZeroNet bootstrap process failed."""
[docs]class FreenetBootstrapFailed(_BaseWarning): """Freenet bootstrap process failed."""
[docs]class RedisCommandFailed(_BaseWarning): """Redis command execution failed."""
[docs]class DatabaseOperaionFailed(_BaseWarning): """Database operation execution failed."""
[docs]class APIRequestFailed(_BaseWarning): """API submit failed."""
[docs]class SiteNotFoundWarning(_BaseWarning, ImportWarning): """Site customisation not found."""
[docs]class LockWarning(_BaseWarning): """Failed to acquire Redis lock."""
[docs]class HookExecutionFailed(_BaseWarning): """Failed to execute hook function."""