28
28
)
29
29
30
30
try :
31
- from ipfshttpclient .exceptions import (
32
- ConnectionError as IpfsConnectionError ,
33
- )
31
+ from ipfshttpclient .exceptions import ConnectionError as IpfsConnectionError
34
32
except ImportError :
35
33
pass
36
34
37
- logger = logging .getLogger ("ethpm.utils.backend" )
38
35
39
- IPFS_NODE_UNAVAILABLE_MSG = "No local IPFS node available on port 5001."
36
+ logger = logging . getLogger ( "ethpm.utils.backend" )
40
37
41
38
ALL_URI_BACKENDS = [
42
39
InfuraIPFSBackend ,
47
44
]
48
45
49
46
47
+ def _handle_optional_ipfs_backend_exception (e : Exception ) -> None :
48
+ try :
49
+ # if optional `ipfshttpclient` module is present, catch and debug if
50
+ # IpfsConnectionError, else raise original exception.
51
+ if isinstance (e , IpfsConnectionError ):
52
+ logger .debug ("No local IPFS node available on port 5001." , exc_info = True )
53
+ else :
54
+ raise e
55
+ except NameError :
56
+ # if optional `ipfshttpclient` module is not present, raise original exception
57
+ raise e
58
+
59
+
50
60
@to_tuple
51
61
def get_translatable_backends_for_uri (
52
62
uri : URI ,
@@ -56,8 +66,8 @@ def get_translatable_backends_for_uri(
56
66
try :
57
67
if backend ().can_translate_uri (uri ): # type: ignore
58
68
yield backend
59
- except IpfsConnectionError :
60
- logger . debug ( IPFS_NODE_UNAVAILABLE_MSG , exc_info = True )
69
+ except Exception as e :
70
+ _handle_optional_ipfs_backend_exception ( e )
61
71
62
72
63
73
@to_tuple
@@ -77,5 +87,5 @@ def get_resolvable_backends_for_uri(
77
87
try :
78
88
if backend_class ().can_resolve_uri (uri ): # type: ignore
79
89
yield backend_class
80
- except IpfsConnectionError :
81
- logger . debug ( IPFS_NODE_UNAVAILABLE_MSG , exc_info = True )
90
+ except Exception as e :
91
+ _handle_optional_ipfs_backend_exception ( e )
0 commit comments