pinecone.core.utils.error_handling
1import inspect 2from functools import wraps 3 4from urllib3.exceptions import MaxRetryError, ProtocolError 5 6from pinecone import Config, PineconeProtocolError 7 8 9def validate_and_convert_errors(func): 10 @wraps(func) 11 def inner_func(*args, **kwargs): 12 Config.validate() # raises exceptions in case of invalid config 13 try: 14 return func(*args, **kwargs) 15 except MaxRetryError as e: 16 if isinstance(e.reason, ProtocolError): 17 raise PineconeProtocolError( 18 f"Failed to connect to {e.url}; did you specify the correct index name?" 19 ) from e 20 else: 21 raise 22 except ProtocolError as e: 23 raise PineconeProtocolError(f"Failed to connect; did you specify the correct index name?") from e 24 25 # Override signature 26 sig = inspect.signature(func) 27 inner_func.__signature__ = sig 28 return inner_func
def
validate_and_convert_errors(func):
10def validate_and_convert_errors(func): 11 @wraps(func) 12 def inner_func(*args, **kwargs): 13 Config.validate() # raises exceptions in case of invalid config 14 try: 15 return func(*args, **kwargs) 16 except MaxRetryError as e: 17 if isinstance(e.reason, ProtocolError): 18 raise PineconeProtocolError( 19 f"Failed to connect to {e.url}; did you specify the correct index name?" 20 ) from e 21 else: 22 raise 23 except ProtocolError as e: 24 raise PineconeProtocolError(f"Failed to connect; did you specify the correct index name?") from e 25 26 # Override signature 27 sig = inspect.signature(func) 28 inner_func.__signature__ = sig 29 return inner_func