Skip to content

Commit

Permalink
docs: add exceptions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdang committed Aug 15, 2022
1 parent a5734c5 commit fe3e2f4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
26 changes: 26 additions & 0 deletions ape_alchemy/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Tuple

from ape.exceptions import ProviderError


class AlchemyProviderError(ProviderError):
"""
An error raised by the Alchemy provider plugin.
"""


class AlchemyFeatureNotAvailable(AlchemyProviderError):
"""
An error raised when trying to use a feature that is unavailable
on the user's tier or network.
"""


class MissingProjectKeyError(AlchemyProviderError):
"""
An error raised when there is no API key set.
"""

def __init__(self, options: Tuple[str, ...]):
env_var_str = ", ".join([f"${n}" for n in options])
super().__init__(f"Must set one of {env_var_str}.")
27 changes: 3 additions & 24 deletions ape_alchemy/providers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Any, Dict, Iterator, Tuple
from typing import Any, Dict, Iterator

from ape.api import UpstreamProvider, Web3Provider
from ape.exceptions import ContractLogicError, ProviderError, VirtualMachineError
Expand All @@ -11,36 +11,15 @@
from web3.middleware import geth_poa_middleware
from web3.types import RPCEndpoint

from .exceptions import AlchemyFeatureNotAvailable, AlchemyProviderError, MissingProjectKeyError

_ETH_ENVIRONMENT_VARIABLE_NAMES = ("WEB3_ALCHEMY_PROJECT_ID", "WEB3_ALCHEMY_API_KEY")
_ARB_ENVIRONMENT_VARIABLE_NAMES = (
"WEB3_ARBITRUM_ALCHEMY_PROJECT_ID",
"WEB3_ARBITRUM_ALCHEMY_API_KEY",
)


class AlchemyProviderError(ProviderError):
"""
An error raised by the Alchemy provider plugin.
"""


class AlchemyFeatureNotAvailable(AlchemyProviderError):
"""
An error raised when trying to use a feature that is unavailable
on the user's tier or network.
"""


class MissingProjectKeyError(AlchemyProviderError):
"""
An error raised when there is no API key set.
"""

def __init__(self, options: Tuple[str, ...]):
env_var_str = ", ".join([f"${n}" for n in options])
super().__init__(f"Must set one of {env_var_str}.")


class AlchemyEthereumProvider(Web3Provider, UpstreamProvider):
"""
A web3 provider using an HTTP connection to Alchemy.
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
:maxdepth: 1
methoddocs/providers.md
methoddocs/exceptions.md
```
6 changes: 6 additions & 0 deletions docs/methoddocs/exceptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Exceptions

```{eval-rst}
.. automodule:: ape_alchemy.exceptions
:members:
```

0 comments on commit fe3e2f4

Please sign in to comment.