Skip to content

Commit

Permalink
fix: improve error message when URI missing (#2491)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Feb 5, 2025
1 parent 9073707 commit db009cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
additional_dependencies: [flake8-breakpoint, flake8-print, flake8-pydantic, flake8-type-checking]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies: [
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"lint": [
"black>=24.10.0,<25", # Auto-formatter and linter
"mypy>=1.13.0,<2", # Static type analyzer
"mypy>=1.14.1,<1.15.0", # Static type analyzer
"types-PyYAML", # Needed due to mypy typeshed
"types-requests", # Needed due to mypy typeshed
"types-setuptools", # Needed due to mypy typeshed
Expand Down
4 changes: 3 additions & 1 deletion src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ def uri(self) -> str:
# NOTE: Don't use default IPC path here. IPC must be
# configured if it is the only RPC.

raise ProviderError("Missing URI.")
raise ProviderError(
f"Missing URI for network '{self.network.name}' on '{self.network.ecosystem.name}'."
)

@property
def network_choice(self) -> str:
Expand Down
29 changes: 27 additions & 2 deletions tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from abc import ABC
from pathlib import Path
from typing import cast
from typing import Optional, cast

import pytest
from eth_pydantic_types import HashBytes32
Expand All @@ -12,6 +13,7 @@
from web3.exceptions import ExtraDataLengthError
from web3.providers import HTTPProvider

from ape.api import NetworkAPI
from ape.exceptions import (
APINotImplementedError,
BlockNotFoundError,
Expand All @@ -26,7 +28,7 @@
from ape.utils import to_int
from ape.utils._web3_compat import ExtraDataToPOAMiddleware
from ape_ethereum.ecosystem import Block
from ape_ethereum.provider import DEFAULT_SETTINGS, EthereumNodeProvider
from ape_ethereum.provider import DEFAULT_SETTINGS, EthereumNodeProvider, Web3Provider
from ape_ethereum.trace import TraceApproach
from ape_ethereum.transactions import (
AccessList,
Expand Down Expand Up @@ -143,6 +145,29 @@ def test_uri_invalid(geth_provider, project, ethereum):
geth_provider.provider_settings = settings


def test_uri_missing(mock_sepolia):
class MyProvider(Web3Provider, ABC):
network: NetworkAPI = mock_sepolia
name: str = "devnode"
_connected_uri = None
_configured_rpc = None

@property
def _default_http_uri(self) -> Optional[str]:
# Doing this to get the error to occur.
return None

def connect(self):
pass

def disconnect(self):
pass

provider = MyProvider()
with pytest.raises(ProviderError, match="Missing URI for network 'sepolia' on 'ethereum'."):
_ = provider.uri


@geth_process_test
def test_repr_connected(geth_provider):
actual = repr(geth_provider)
Expand Down

0 comments on commit db009cc

Please sign in to comment.