Skip to content

Commit 4dd52c7

Browse files
committed
Remove redundant web3.exceptions.PMError in favor of ethpm.exceptions.PyEthPMException
1 parent 2e2f2d9 commit 4dd52c7

File tree

7 files changed

+37
-43
lines changed

7 files changed

+37
-43
lines changed

ethpm/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ class ManifestBuildingError(PyEthPMException):
5353
"""
5454

5555
pass
56+
57+
58+
class ManifestValidationError(PyEthPMException):
59+
"""
60+
Raised when a provided manifest cannot be published, since it's invalid.
61+
"""
62+
63+
pass

ethpm/package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
EthPMValidationError,
5757
FailureToFetchIPFSAssetsError,
5858
InsufficientAssetsError,
59-
PyEthPMError,
59+
PyEthPMException,
6060
)
6161
from ethpm.uri import (
6262
resolve_uri_contents,
@@ -338,7 +338,7 @@ def build_dependencies(self) -> "Dependencies":
338338
try:
339339
validate_build_dependency(name, uri)
340340
dependency_package = Package.from_uri(uri, self.w3)
341-
except PyEthPMError as e:
341+
except PyEthPMException as e:
342342
raise FailureToFetchIPFSAssetsError(
343343
f"Failed to retrieve build dependency: {name} from URI: {uri}.\n"
344344
f"Got error: {e}."

newsfragments/1478.breaking.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
All exceptions inherit from a custom class. EthPM exceptions inherit from PyEthPMError, ENS exceptions inherit from ENS Error, and all other web3.py exceptions inherit from Web3Exception
1+
All exceptions inherit from a custom class. EthPM exceptions inherit from PyEthPMException, ENS exceptions inherit from ENSException, and all other web3.py exceptions inherit from Web3Exception

tests/core/pm-module/test_pm_init.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
)
77
from ethpm.exceptions import (
88
InsufficientAssetsError,
9+
PyEthPMException,
910
)
1011
from ethpm.tools import (
1112
get_ethpm_local_manifest,
1213
get_ethpm_spec_manifest,
1314
)
14-
from web3.exceptions import (
15-
PMError,
16-
)
1715

1816

1917
def test_pm_init_with_minimal_manifest(w3):
@@ -123,10 +121,10 @@ def test_get_local_package(w3, tmp_ethpmdir):
123121
def test_get_local_package_with_invalid_ethpmdir(w3, tmp_path):
124122
invalid_ethpmdir = tmp_path / "invalid"
125123
invalid_ethpmdir.mkdir()
126-
with pytest.raises(PMError, match="not a valid ethPM packages directory."):
124+
with pytest.raises(PyEthPMException, match="not a valid ethPM packages directory."):
127125
w3.pm.get_local_package("owned", invalid_ethpmdir)
128126

129127

130128
def test_get_local_package_with_uninstalled_package(w3, tmp_ethpmdir):
131-
with pytest.raises(PMError, match="Package: safe-math not found in "):
129+
with pytest.raises(PyEthPMException, match="Package: safe-math not found in "):
132130
w3.pm.get_local_package("safe-math", tmp_ethpmdir)

tests/core/pm-module/test_registry_integration.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from ethpm.contract import (
1212
LinkableContract,
1313
)
14-
from web3 import Web3
15-
from web3.exceptions import (
16-
PMError,
14+
from ethpm.exceptions import (
15+
PyEthPMException,
1716
)
17+
from web3 import Web3
1818
from web3.pm import (
1919
SimpleRegistry,
2020
get_simple_registry_manifest,
@@ -60,25 +60,25 @@ def test_pm_set_custom_registry(empty_sol_registry, fresh_w3):
6060

6161
@pytest.mark.xfail(reason="Need to properly add authorization as of 8/10/2022")
6262
def test_pm_must_set_registry_before_all_registry_interaction_functions(fresh_w3):
63-
with pytest.raises(PMError):
63+
with pytest.raises(PyEthPMException):
6464
fresh_w3.pm.release_package(
6565
"package", "1.0.0", "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR"
6666
)
67-
with pytest.raises(PMError):
67+
with pytest.raises(PyEthPMException):
6868
fresh_w3.pm.get_release_id_data(b"invalid_release_id")
69-
with pytest.raises(PMError):
69+
with pytest.raises(PyEthPMException):
7070
fresh_w3.pm.get_release_id("package", "1.0.0")
71-
with pytest.raises(PMError):
71+
with pytest.raises(PyEthPMException):
7272
fresh_w3.pm.get_release_data("package", "1.0.0")
73-
with pytest.raises(PMError):
73+
with pytest.raises(PyEthPMException):
7474
fresh_w3.pm.get_package("package", "1.0.0")
75-
with pytest.raises(PMError):
75+
with pytest.raises(PyEthPMException):
7676
fresh_w3.pm.get_all_package_names()
77-
with pytest.raises(PMError):
77+
with pytest.raises(PyEthPMException):
7878
fresh_w3.pm.get_all_package_releases("package")
79-
with pytest.raises(PMError):
79+
with pytest.raises(PyEthPMException):
8080
fresh_w3.pm.get_release_count("package")
81-
with pytest.raises(PMError):
81+
with pytest.raises(PyEthPMException):
8282
fresh_w3.pm.get_package_count()
8383

8484

web3/exceptions.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,6 @@ class TimeExhausted(Web3Exception):
201201
pass
202202

203203

204-
class PMError(Web3Exception):
205-
"""
206-
Raised when an error occurs in the PM module.
207-
"""
208-
209-
pass
210-
211-
212-
class ManifestValidationError(PMError):
213-
"""
214-
Raised when a provided manifest cannot be published, since it's invalid.
215-
"""
216-
217-
pass
218-
219-
220204
class TransactionNotFound(Web3Exception):
221205
"""
222206
Raised when a tx hash used to lookup a tx in a jsonrpc call cannot be found.

web3/pm.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
ASSETS_DIR,
3939
Package,
4040
)
41+
from ethpm.exceptions import (
42+
PyEthPMException,
43+
ManifestValidationError,
44+
)
4145
from ethpm.uri import (
4246
is_supported_content_addressed_uri,
4347
resolve_uri_contents,
@@ -56,9 +60,7 @@
5660
)
5761
from web3.exceptions import (
5862
InvalidAddress,
59-
ManifestValidationError,
6063
NameNotFound,
61-
PMError,
6264
)
6365
from web3.module import (
6466
Module,
@@ -360,11 +362,13 @@ def get_local_package(self, package_name: str, ethpm_dir: Path = None) -> Packag
360362
ethpm_dir = Path.cwd() / "_ethpm_packages"
361363

362364
if not ethpm_dir.name == "_ethpm_packages" or not ethpm_dir.is_dir():
363-
raise PMError(f"{ethpm_dir} is not a valid ethPM packages directory.")
365+
raise PyEthPMException(
366+
f"{ethpm_dir} is not a valid ethPM packages directory."
367+
)
364368

365369
local_packages = [pkg.name for pkg in ethpm_dir.iterdir() if pkg.is_dir()]
366370
if package_name not in local_packages:
367-
raise PMError(
371+
raise PyEthPMException(
368372
f"Package: {package_name} not found in {ethpm_dir}. "
369373
f"Available packages include: {local_packages}."
370374
)
@@ -402,7 +406,7 @@ def set_registry(self, address: Union[Address, ChecksumAddress, ENS]) -> None:
402406
)
403407
self.registry = SimpleRegistry(addr_lookup, self.w3)
404408
else:
405-
raise PMError(
409+
raise PyEthPMException(
406410
"Expected a canonical/checksummed address or ENS name for the address, "
407411
f"instead received {type(address)}."
408412
)
@@ -555,14 +559,14 @@ def _validate_set_registry(self) -> None:
555559
try:
556560
self.registry
557561
except AttributeError:
558-
raise PMError(
562+
raise PyEthPMException(
559563
"web3.pm does not have a set registry. "
560564
"Please set registry with either: "
561565
"web3.pm.set_registry(address) or "
562566
"web3.pm.deploy_and_set_registry()"
563567
)
564568
if not isinstance(self.registry, ERC1319Registry):
565-
raise PMError(
569+
raise PyEthPMException(
566570
"web3.pm requires an instance of a subclass of ERC1319Registry "
567571
"to be set as the web3.pm.registry attribute. Instead found: "
568572
f"{type(self.registry)}."

0 commit comments

Comments
 (0)