def _convert_exception(self, exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. *args: additional args from the raising site. **kwargs: additional keyword args from the raising site. Returns: Api interface exceptions - dbexceptions with new args. """ kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs) exc.args += args if kwargs_as_str: exc.args += kwargs_as_str, new_args = (type(exc).__name__,) + exc.args if isinstance(exc, gorpc.TimeoutError): new_exc = dbexceptions.TimeoutError(new_args) elif isinstance(exc, vtgate_utils.VitessError): new_exc = exc.convert_to_dbexception(new_args) elif isinstance(exc, gorpc.ProgrammingError): new_exc = dbexceptions.ProgrammingError(new_args) elif isinstance(exc, gorpc.GoRpcError): new_exc = dbexceptions.FatalError(new_args) else: new_exc = exc vtgate_utils.log_exception( new_exc, keyspace=kwargs.get('keyspace'), tablet_type=kwargs.get('tablet_type')) return new_exc
def _convert_exception(self, exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. *args: additional args from the raising site. **kwargs: additional keyword args from the raising site. Returns: Api interface exceptions - dbexceptions with new args. """ new_args = exc.args + (str(self), ) + args if kwargs: new_args += tuple(sorted(kwargs.itervalues())) new_exc = exc if isinstance(exc, gorpc.TimeoutError): new_exc = dbexceptions.TimeoutError(new_args) elif isinstance(exc, vtgate_utils.VitessError): new_exc = exc.convert_to_dbexception(new_args) elif isinstance(exc, gorpc.ProgrammingError): new_exc = dbexceptions.ProgrammingError(new_args) elif isinstance(exc, gorpc.GoRpcError): new_exc = dbexceptions.FatalError(new_args) keyspace_name = kwargs.get('keyspace', None) tablet_type = kwargs.get('tablet_type', None) vtgate_utils.log_exception(new_exc, keyspace=keyspace_name, tablet_type=tablet_type) return new_exc
def convert_exception(exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. args: additional args from the raising site. kwargs: additional keyword args from the raising site. Returns: Api interface exceptions - dbexceptions with new args. """ new_args = exc.args + args if kwargs: new_args += tuple(kwargs.itervalues()) new_exc = exc if isinstance(exc, gorpc.TimeoutError): new_exc = dbexceptions.TimeoutError(new_args) elif isinstance(exc, gorpc.AppError): new_exc = handle_app_error(new_args) elif isinstance(exc, gorpc.ProgrammingError): new_exc = dbexceptions.ProgrammingError(new_args) elif isinstance(exc, gorpc.GoRpcError): new_exc = dbexceptions.FatalError(new_args) keyspace_name = kwargs.get('keyspace', None) tablet_type = kwargs.get('tablet_type', None) vtgate_utils.log_exception(new_exc, keyspace=keyspace_name, tablet_type=tablet_type) return new_exc
def convert_exception(exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. args: additional args from the raising site. kwargs: additional keyword args from the raising site. Returns: Api interface exceptions - dbexceptions with new args. """ new_args = exc.args + args if kwargs: new_args += tuple(kwargs.itervalues()) new_exc = exc if isinstance(exc, gorpc.TimeoutError): new_exc = dbexceptions.TimeoutError(new_args) elif isinstance(exc, gorpc.AppError): new_exc = handle_app_error(new_args) elif isinstance(exc, gorpc.ProgrammingError): new_exc = dbexceptions.ProgrammingError(new_args) elif isinstance(exc, gorpc.GoRpcError): new_exc = dbexceptions.FatalError(new_args) keyspace = kwargs.get("keyspace", None) tablet_type = kwargs.get("tablet_type", None) vtgate_utils.log_exception(new_exc, keyspace=keyspace, tablet_type=tablet_type) return new_exc
def _convert_exception(exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. *args: additional args from the raising site. **kwargs: additional keyword args from the raising site. They will be converted into a single string, and added as an extra arg to the exception. Returns: Api interface exceptions - dbexceptions with new args. """ kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs) exc.args += args if kwargs_as_str: exc.args += kwargs_as_str, new_args = (type(exc).__name__, ) + exc.args if isinstance(exc, vtgate_utils.VitessError): new_exc = exc.convert_to_dbexception(new_args) elif isinstance(exc, grpc.RpcError): # Most RpcErrors should also implement Call so we can get details. if isinstance(exc, grpc.Call): code = exc.code() details = exc.details() if code == grpc.StatusCode.DEADLINE_EXCEEDED: new_exc = dbexceptions.TimeoutError(new_args) elif code == grpc.StatusCode.UNAVAILABLE: if vtgate_utils.throttler_err_re.search(details): return dbexceptions.ThrottledError(new_args) else: return dbexceptions.TransientError(new_args) elif code == grpc.StatusCode.ALREADY_EXISTS: new_exc = _prune_integrity_error(details, new_args) elif code == grpc.StatusCode.FAILED_PRECONDITION: return dbexceptions.QueryNotServed(details, new_args) elif code == grpc.StatusCode.INVALID_ARGUMENT: return dbexceptions.ProgrammingError(details, new_args) else: # Other RPC error that we don't specifically handle. new_exc = dbexceptions.DatabaseError(new_args + (code, details)) else: # RPC error that doesn't provide code and details. # Don't let gRPC-specific errors leak beyond this package. new_exc = dbexceptions.DatabaseError(new_args + (exc, )) else: new_exc = exc vtgate_utils.log_exception(new_exc, keyspace=kwargs.get('keyspace'), tablet_type=kwargs.get('tablet_type')) return new_exc
def _convert_exception(exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. *args: additional args from the raising site. **kwargs: additional keyword args from the raising site. They will be converted into a single string, and added as an extra arg to the exception. Returns: Api interface exceptions - dbexceptions with new args. """ kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs) exc.args += args if kwargs_as_str: exc.args += kwargs_as_str, new_args = (type(exc).__name__,) + exc.args if isinstance(exc, vtgate_utils.VitessError): new_exc = exc.convert_to_dbexception(new_args) elif isinstance(exc, grpc.RpcError): # Most RpcErrors should also implement Call so we can get details. if isinstance(exc, grpc.Call): code = exc.code() details = exc.details() if code == grpc.StatusCode.DEADLINE_EXCEEDED: new_exc = dbexceptions.TimeoutError(new_args) elif code == grpc.StatusCode.UNAVAILABLE: if vtgate_utils.throttler_err_re.search(details): return dbexceptions.ThrottledError(new_args) else: return dbexceptions.TransientError(details, new_args) elif code == grpc.StatusCode.ALREADY_EXISTS: new_exc = _prune_integrity_error(details, new_args) elif code == grpc.StatusCode.FAILED_PRECONDITION: return dbexceptions.QueryNotServed(details, new_args) elif code == grpc.StatusCode.INVALID_ARGUMENT: return dbexceptions.ProgrammingError(details, new_args) else: # Other RPC error that we don't specifically handle. new_exc = dbexceptions.DatabaseError(new_args + (code, details)) else: # RPC error that doesn't provide code and details. # Don't let gRPC-specific errors leak beyond this package. new_exc = dbexceptions.DatabaseError(new_args + (exc,)) else: new_exc = exc vtgate_utils.log_exception( new_exc, keyspace=kwargs.get('keyspace'), tablet_type=kwargs.get('tablet_type')) return new_exc
def _convert_exception(exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. *args: additional args from the raising site. **kwargs: additional keyword args from the raising site. They will be converted into a single string, and added as an extra arg to the exception. Returns: Api interface exceptions - dbexceptions with new args. """ kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs) exc.args += args if kwargs_as_str: exc.args += kwargs_as_str, new_args = (type(exc).__name__,) + exc.args if isinstance(exc, vtgate_utils.VitessError): new_exc = exc.convert_to_dbexception(new_args) elif isinstance(exc, face.ExpirationError): # face.ExpirationError is returned by the gRPC library when # a request times out. Note it is a subclass of face.AbortionError # so we have to test for it before. new_exc = dbexceptions.TimeoutError(new_args) elif isinstance(exc, face.AbortionError): # face.AbortionError is the toplevel error returned by gRPC for any # RPC that finishes earlier than expected. msg = exc.details if exc.code == interfaces.StatusCode.UNAVAILABLE: if _throttler_err_pattern.search(msg): return dbexceptions.ThrottledError(new_args) else: return dbexceptions.TransientError(new_args) elif exc.code == interfaces.StatusCode.ALREADY_EXISTS: new_exc = _prune_integrity_error(msg, new_args) elif exc.code == interfaces.StatusCode.FAILED_PRECONDITION: return dbexceptions.QueryNotServed(msg, new_args) else: # Unhandled RPC application error new_exc = dbexceptions.DatabaseError(new_args + (msg,)) else: new_exc = exc vtgate_utils.log_exception( new_exc, keyspace=kwargs.get('keyspace'), tablet_type=kwargs.get('tablet_type')) return new_exc
def _convert_exception(exc, *args, **kwargs): """This parses the protocol exceptions to the api interface exceptions. This also logs the exception and increments the appropriate error counters. Args: exc: raw protocol exception. *args: additional args from the raising site. **kwargs: additional keyword args from the raising site. Returns: Api interface exceptions - dbexceptions with new args. """ kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs) exc.args += args if kwargs_as_str: exc.args += kwargs_as_str, new_args = (type(exc).__name__,) + exc.args if isinstance(exc, vtgate_utils.VitessError): new_exc = exc.convert_to_dbexception(new_args) elif isinstance(exc, face.ExpirationError): new_exc = dbexceptions.TimeoutError(new_args) elif isinstance(exc, face.AbortionError): msg = exc.details if exc.code == interfaces.StatusCode.UNAVAILABLE: if _throttler_err_pattern.search(msg): return dbexceptions.ThrottledError(new_args) else: return dbexceptions.TransientError(new_args) elif exc.code == interfaces.StatusCode.ALREADY_EXISTS: new_exc = _prune_integrity_error(msg, new_args) else: # Unhandled RPC application error new_exc = dbexceptions.DatabaseError(new_args + (msg,)) else: new_exc = exc vtgate_utils.log_exception( new_exc, keyspace=kwargs.get('keyspace'), tablet_type=kwargs.get('tablet_type')) return new_exc